Spring Boot-如何指定备用启动类? (多个入口点) [英] Spring Boot - How to specify an alternate start-class? (Multiple Entry Points)
问题描述
我想在我的Spring-Boot应用程序中添加一个替代入口点.我希望将其保留为肥罐.这可能吗?
I want to add an alternate entry point to my Spring-Boot application. I would prefer to keep this as a fat jar. Is this possible?
根据其文档 ,属性loader.main
指定要启动的主类的名称.
According to their documentation, the property loader.main
specifies the name of the main class to launch.
我尝试了java -jar MyJar.jar --loader.main=com.mycompany.AlternateMain
,但pom.xml中指定的起始类仍在运行(如果我从pom.xml中删除了该类,则在包装过程中会出错).
I tried java -jar MyJar.jar --loader.main=com.mycompany.AlternateMain
but the start-class specified in my pom.xml was still run (and if I remove this from the pom.xml then I error during the packaging).
或者,我尝试了java -cp MyJar.jar com.mycompany.AlternateMain
,但是我不知道一种将所有嵌套jar添加到类路径的好方法.
Alternatively, I tried java -cp MyJar.jar com.mycompany.AlternateMain
but I don't know of a good way to add all the nested jars to the classpath.
有什么建议吗?
这是我使用的解决方案
按照jst的建议,我将启动器更改为使用PropertiesLauncher.我通过修改spring-boot-maven-plugin的配置来做到这一点.
As jst suggested, I changed my launcher to use the PropertiesLauncher. I did this by modifying the configuration of my spring-boot-maven-plugin.
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>${start-class}</mainClass>
<layout>ZIP</layout>
...
<layout>ZIP</layout>
触发Spring Boot以使用PropertiesLauncher
.
我创建了我的胖子罐(mvn包),然后像这样称呼备用主罐:
I created my fat jar (mvn package) then called the alternate main like this:
java -jar -Dloader.main=com.mycompany.AlternateMain MyJar.jar
感谢您的帮助!
推荐答案
我不认为该属性适用于您的情况.有3种不同的启动程序"(回到文档中查看).如果要构建jar,则它将使用JarLauncher类.如果将其切换到PropertiesLauncher,则loader.main将很有用.
I don't believe that property would apply in your case. There are 3 different "Launchers" (go back to the docs and see). If you are building a jar it uses the JarLauncher class. If you switch it to PropertiesLauncher then loader.main would be useful.
META-INF/MANIFEST.MF
META-INF/MANIFEST.MF
Main-Class: org.springframework.boot.loader.PropertiesLauncher
这篇关于Spring Boot-如何指定备用启动类? (多个入口点)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!