在运行时将jar文件添加到spring-boot类路径 [英] Add jar file to spring-boot classpath at runtime
问题描述
我想使用 spring-boot 和插件开发一个模块化应用程序.插件将使用 spring-plugin 处理,它们存储在目录中的jar文件中(例如:/home/application/plugins).如何在运行时将jar文件添加到应用程序类路径中并加载这些jar文件中的类和bean(插件). 最好的问候,HLicea
I want develop a modular application using spring-boot and plugins. The plugins will be handled with spring-plugin and these are stored in jars files in a directory (for example: /home/application/plugins).How can I add jars files to the application classpath at runtime and loading classes and beans (plugins) that are in these jars files. Best regards, HLicea
推荐答案
您需要使用PropertiesLauncher而不是JarLauncher:
You need to use PropertiesLauncher instead of JarLauncher:
java -cp "yourBoot.jar" -Dloader.path=plugins/ -Dloader.main=your.mainClass org.springframework.boot.loader.PropertiesLauncher
这将使Java将plugins目录中的jar加载到上下文中,并将这些jar中标记为@Configuration的所有类都加载到上下文中.
This will make java load the jars in the plugins directory and spring load all the classes in those jars marked as @Configuration into the context.
这篇关于在运行时将jar文件添加到spring-boot类路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!