Disabling Spring JMS Auto configuration in Spring Boot Application
Asked Answered
N

4

27

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?

Ned answered 22/10, 2015 at 7:1 Comment(1)
Note to future Apache Tomcat Java WAR deploying viewers, if you see an error with Caused by: java.lang.NoSuchMethodException: org.springframework.jms.annotation.JmsBootstrapConfiguration$$EnhancerBySpringCGLIB$$9f8a2d0.CGLIB$SET_THREAD_CALLBACKS([Lorg.springframework.cglib.proxy.Callback;) in catalina.out, you can try out some of these answers below.Technician
P
31

You can add the auto configurations, which you want to disable, to the SpringBootApplication annotation:

@SpringBootApplication(exclude = JmsAutoConfiguration.class)
Previous answered 22/10, 2015 at 7:44 Comment(1)
Or: @EnableAutoConfiguration(exclude = JmsAutoConfiguration.class)Marte
O
20

FYI, use this to disable ActiveMQ

@SpringBootApplication(exclude = ActiveMQAutoConfiguration.class)
Obeah answered 26/12, 2016 at 5:29 Comment(0)
C
16

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
Clockmaker answered 22/8, 2016 at 16:58 Comment(0)
I
6

In my case it worked after excluding both classes :

 @EnableAutoConfiguration(exclude={JmsAutoConfiguration.class, ActiveMQAutoConfiguration.class})
Infielder answered 30/7, 2020 at 8:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.