【问题标题】:Disable JMS for profile为配置文件禁用 JMS
【发布时间】:2019-03-26 14:07:14
【问题描述】:

在 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 监听器仍在启动。

【问题讨论】:

  • 如何在运行时激活配置文件?
  • 只是通过命令行--spring.profiles.active=lala,但我不想直接公开--spring.profiles.active=lala,nojms,因为这会影响我无法控制的各种容器构建

标签: spring-boot spring-jms


【解决方案1】:

当您通过 CLI 参数激活时,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

spring.profiles.active 属性遵循与其他属性相同的排序规则:最高的 PropertySource 获胜。这意味着您可以在 application.properties 中指定活动配置文件,然后使用命令行开关替换它们。

有时,将特定于配置文件的属性添加到活动配置文件而不是替换它们很有用。 spring.profiles.include 属性可用于无条件添加活动配置文件。 SpringApplication 入口点还有一个用于设置附加配置文件的 Java API(即,在那些由 s​​pring.profiles.active 属性激活的配置文件之上)。请参阅 SpringApplication 中的 setAdditionalProfiles() 方法。

spring:
  main:
    web-application-type: none

  profiles:
      include: nojms

【讨论】:

    猜你喜欢
    • 2011-12-29
    • 1970-01-01
    • 2012-04-17
    • 1970-01-01
    • 2011-02-20
    • 2019-05-15
    • 2016-01-21
    • 2019-04-01
    • 1970-01-01
    相关资源
    最近更新 更多