使用配置文件在Spring Boot应用程序中启用或禁用@EnableJms

问题描述 投票:0回答:1

给出下面的spring / boot应用程序。

@SpringBootApplication
@Configuration
@ComponentScan
@EnableGlobalMethodSecurity(
        prePostEnabled = true,
        securedEnabled = false,
        jsr250Enabled = false)

@EnableJms // we would like to control this from an application property on/off
public class PayZilchCustomerServiceApplication {
    static {
        SSLUtilities.trustAllHostnames();
        SSLUtilities.trustAllHttpsCertificates();
    }
    public static void main(String[] args) {
        SpringApplication.run(PayZilchCustomerServiceApplication.class, args);
    }
}

我们发现对于某些本地调试方案,我们希望关闭@EnableJms。我们注释掉代码行。我们有时会创建带有注释行的PR。 PR正在通过代码审查来捕获。

将要经过一天。我们如何从应用程序属性文件控制@EnableJms,最好是默认情况下它处于打开状态,但可以通过application-local.properties条目将其关闭。

java spring spring-boot spring-jms
1个回答
0
投票

创建一个新类,并使用以下3个注释进行标记:

@Configuration
@EnableJms
@ConditionalOnProperty(name = "turnonjms", havingValue = "true")
public class EnableMyJmsClass {
   //you can keep it empty. Just make sure this is present in the same folder where main class is
}
© www.soinside.com 2019 - 2024. All rights reserved.