Spring Boot: Refresh Application Context on Classpath Changes

Viewed 512

I've built a small Application using Spring Boot's PropertiesLauncher in conjunction with Loader-Path: plugins Manifest Entry. There are several jar files inside the plugins folder containing META-INF/spring.factories.

Loading the Configuration of my external plugin jars works as expected.

Now I wonder if and how I could refresh the application context if something on the classpath changes. For example deleting or adding an external plugin jar.

I've already took a look into SpringApplicationRunListener but I guess I cannot realize it with this class.

Any ideas if and how it is possible?

1 Answers

With plain Spring changing jars on the class path usually means full application restart. There is no out of the box mechanism to support runtime changes in the class path provided Spring Framework.

In 2009/2010 there was Spring Dynamics Modules project but it seems abandoned now.

You most likely would have to implement this from scratch yourself. Perhaps you should look into an existing plugin system implementation e.g. Apache Felix which implements OSGi:

Apache Felix is a community effort to implement the OSGi Framework and Service platform and other interesting OSGi-related technologies under the Apache license. The OSGi specifications originally targeted embedded devices and home services gateways, but they are ideally suited for any project interested in the principles of modularity, component-orientation, and/or service-orientation. OSGi technology combines aspects of these aforementioned principles to define a dynamic service deployment framework that is amenable to remote management.

Related