简体   繁体   English

在 Spring Boot 应用程序中禁用 Spring JMS 自动配置

[英]Disabling Spring JMS Auto configuration in Spring Boot Application

In my spring boot application i configure two different instances of MQQueueConnectionFactory (different id) as it is a need of the application.在我的 Spring Boot 应用程序中,我配置了两个不同的 MQQueueConnectionFactory 实例(不同的 id),因为它是应用程序的需要。 For that i have added ibm client jars.为此,我添加了 ibm 客户端 jar。

I have also added spring-jms dependency in my code as i wanted JmsTemplate etc classes.我还在我的代码中添加了 spring-jms 依赖项,因为我想要 JmsTemplate 等类。 After adding this dependency, JmsAutoConfiguration finds JmsTemplate in classpath and tries to configure beans.添加此依赖项后,JmsAutoConfiguration 在类路径中找到 JmsTemplate 并尝试配置 bean。 In this process, it tries to inject bean of type ConnectionFactory and this is where the code fails and i start getting the error.在这个过程中,它尝试注入 ConnectionFactory 类型的 bean,这是代码失败的地方,我开始收到错误消息。 Below is the code from JmsAutoConfiguration下面是来自 JmsAutoConfiguration 的代码

@Configuration
@ConditionalOnClass(JmsTemplate.class)
@ConditionalOnBean(ConnectionFactory.class)
@EnableConfigurationProperties(JmsProperties.class)
@Import(JmsAnnotationDrivenConfiguration.class)
public class JmsAutoConfiguration {

    @Autowired
    private JmsProperties properties;

    @Autowired
    private ConnectionFactory connectionFactory;

    @Autowired(required = false)
    private DestinationResolver destinationResolver;

Do i have a facility to switch off JmsAutoconfiguration feature of spring boot by any chance?我是否可以随时关闭 Spring Boot 的 JmsAutoconfiguration 功能? If not then what is the alternative solution for this?如果不是,那么对此的替代解决方案是什么?

您可以将要禁用的自动配置添加到 SpringBootApplication 注释中:

@SpringBootApplication(exclude = JmsAutoConfiguration.class)

if want to control it via the properties (in this case a application.yml) then you can do something like this.如果想通过属性(在这种情况下是 application.yml)控制它,那么你可以做这样的事情。

spring:
  autoconfigure:
    exclude: org.springframework.boot.autoconfigure.jms.JmsAutoConfiguration

仅供参考,使用它来禁用ActiveMQ

@SpringBootApplication(exclude = ActiveMQAutoConfiguration.class)

在我的情况下,它在排除两个类后工作:

 @EnableAutoConfiguration(exclude={JmsAutoConfiguration.class, ActiveMQAutoConfiguration.class})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM