简体   繁体   English

Spring Boot热部署jar和取消部署

[英]Spring boot hot deploy jar and undeploy

I'm sorry this is not a typical stackoverflow question, I'm not looking to fix some of my code, but I'm trying to find a solution for my application. 抱歉,这不是一个典型的stackoverflow问题,我不想修复某些代码,但是我正在尝试为我的应用程序找到解决方案。

Context: I'm building an spring boot application that can expose/consume custom APIs (these can be REST or otherwise). 上下文:我正在构建一个可以公开/使用自定义API(可以是REST或其他)的Spring Boot应用程序。 The API connectors can be built and compiled outside the application, following a template. 可以按照模板在应用程序外部构建和编译API连接器。

The problem: I need a way to programatically load code compiled outside the application and run it inside my application with 0 downtime, I also need to be able to undeploy the jar no longer used. 问题:我需要一种方法,以编程方式加载在应用程序外部编译的代码,并在停机时间为0的情况下在我的应用程序内部运行它,我还需要能够取消部署不再使用的jar。

I've used OSGi to achieve something like this, though it only involved making frontend apps packaged in jars available, rather than backend APIs. 我使用的OSGi实现的东西像这样的,虽然它只是参与制作在包装罐前端应用程序可用,而不是后端的API。

First, I created an application with an embedded OSGi runtime (Apache Felix, specifically). 首先,我创建了一个带有嵌入式OSGi运行时(特别是Apache Felix)的应用程序。 These runtimes normally watch a local directory to find jar files they can load automatically; 这些运行时通常会监视本地目录以查找可以自动加载的jar文件。 I used custom code to watch an AWS S3 bucket and loaded them explicitly when new files were uploaded to the bucket. 我使用自定义代码监视AWS S3存储桶,并在将新文件上传到存储桶时显式加载了它们。

I setup listeners in my application for when the runtime loaded or unloaded plugin services that implemented my special marker interface and registered/unregistered them when these events happened. 我在应用程序中设置侦听器,以了解何时运行时加载或卸载了实现我的特殊标记器接口的插件服务 ,并在发生这些事件时对其进行了注册/注销。

When requests would come in, I would determine which plugin the requests were meant for via the request path and load needed files from the plugin archive. 当请求进入时,我将通过请求路径确定请求的目标插件,并从插件档案中加载所需的文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM