简体   繁体   中英

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.

Context: I'm building an spring boot application that can expose/consume custom APIs (these can be REST or otherwise). The API connectors can be built and compiled outside the application, following a template.

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.

I've used OSGi to achieve something like this, though it only involved making frontend apps packaged in jars available, rather than backend APIs.

First, I created an application with an embedded OSGi runtime (Apache Felix, specifically). These runtimes normally watch a local directory to find jar files they can load automatically; I used custom code to watch an AWS S3 bucket and loaded them explicitly when new files were uploaded to the bucket.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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