[英]Multiple Spring Boot application classes with profiles
I have the requirement to be able to run my Spring Boot within a container environment, and as a standalone fat JAR.我需要能够在容器环境中运行我的 Spring Boot,并且作为一个独立的胖 JAR。 In the former mode, the application needs to register itself with Consul as this is used for service discovery, whereas in the later we need to disable this integration completely.
在前一种模式下,应用程序需要向 Consul 注册自己,因为这是用于服务发现的,而在后一种模式中,我们需要完全禁用此集成。
To accomplish this I created 2 Application classes: (I actually used an abstract parent here for the duplicate annotations, but I'm omitting this for brevity)为了实现这一点,我创建了 2 个应用程序类:(我实际上在这里使用了一个抽象父类来进行重复的注释,但为了简洁我省略了这个)
@SpringBootApplication
@EnableDiscoveryClient
@EnableConfigurationProperties
@Profile("!standalone")
public class Application extends SpringApplication {
...
}
and和
@SpringBootApplication(exclude = {
ConsulAutoConfiguration.class, ConsulBusAutoConfiguration.class })
@EnableConfigurationProperties
@Profile("standalone")
public class ApplicationStandalone extends SpringApplication {
...
}
Notice the use of profiles and that the standalone version excludes the auto configuration classes for Consul.请注意配置文件的使用,并且独立版本不包括 Consul 的自动配置类。
When I try to build the JAR via Maven I get the following error:当我尝试通过 Maven 构建 JAR 时,出现以下错误:
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.3.0.M5:repackage (default) on project mio-lmpp-service: Execution default of goal org.springframework.boot:spring-boot-maven-plugin:1.3.0.M5:repackage failed: Unable to find a single main class from the following candidates [tv.nativ.mio.lmpp.ApplicationConfig, tv.nativ.mio.lmpp.ApplicationConfigStandalone] -> [Help 1]
What's the best way round this?最好的方法是什么?
Thanks谢谢
Nick缺口
You have two options你有两个选择
Define main class during the build in spring-boot-maven-plugin
.在
spring-boot-maven-plugin
构建期间定义主类。 You can also parametrize it for the build. 您还可以为构建参数化它。
Define main class on in property file or command line.在属性文件或命令行中定义主类。 But you need to use PropertyLauncher instead of default
org.springframework.boot.loader.JarLauncher
.但是您需要使用PropertyLauncher而不是默认的
org.springframework.boot.loader.JarLauncher
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.