为配置文件禁用 JMS

Disable JMS for profile

在 Springboot 2 中,我可以这样做来禁用嵌入式 servlet 容器:

spring:
  main:
    web-application-type: none

现在我正在寻找类似的设置来禁用 JMS。目前我正在使用配置文件,如下所示:

@Profile("!nojms")
public class MQListener {
...

然后使用内容为 application-lala.yaml

spring:
  main:
    web-application-type: none

  profiles:
    active: nojms

但现在当我使用配置文件 "lala" 时,JMS 侦听器仍在启动。

当您通过 CLI args 激活时,profiles.active 不会被触发,因为您实际上已经激活了配置文件。

您可以将 spring.profiles.include 添加到 application-lala 以无条件激活其他配置文件。

https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-profiles.html#boot-features-adding-active-profiles

The spring.profiles.active property follows the same ordering rules as other properties: The highest PropertySource wins. This means that you can specify active profiles in application.properties and then replace them by using the command line switch.

Sometimes, it is useful to have profile-specific properties that add to the active profiles rather than replace them. The spring.profiles.include property can be used to unconditionally add active profiles. The SpringApplication entry point also has a Java API for setting additional profiles (that is, on top of those activated by the spring.profiles.active property). See the setAdditionalProfiles() method in SpringApplication.

spring:
  main:
    web-application-type: none

  profiles:
      include: nojms