简体   繁体   中英

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. For that i have added ibm client jars.

I have also added spring-jms dependency in my code as i wanted JmsTemplate etc classes. After adding this dependency, JmsAutoConfiguration finds JmsTemplate in classpath and tries to configure beans. In this process, it tries to inject bean of type ConnectionFactory and this is where the code fails and i start getting the error. Below is the code from 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? 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.

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

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

@SpringBootApplication(exclude = ActiveMQAutoConfiguration.class)

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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