Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabling Spring JMS Auto configuration in Spring Boot Application

Tags:

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?

like image 285
user3534483 Avatar asked Oct 22 '15 07:10

user3534483


People also ask

How do I disable auto-configuration in spring boot?

If you find that specific auto-configure classes are being applied that you don't want, you can use the exclude attribute of @EnableAutoConfiguration to disable them. If the class is not on the classpath, you can use the excludeName attribute of the annotation and specify the fully qualified name instead.

What is the use of Enable Auto-Configuration in spring boot?

Spring Boot auto-configuration attempts to automatically configure your Spring application based on the jar dependencies that you have added. For example, if HSQLDB is on your classpath, and you have not manually configured any database connection beans, then Spring Boot auto-configures an in-memory database.

What is a benefit of the auto-configuration preset in spring boot?

Simply put, the Spring Boot auto-configuration helps us automatically configure a Spring application based on the dependencies that are present on the classpath. This can make development faster and easier by eliminating the need to define certain beans included in the auto-configuration classes.

Can we disable the default Web server in the spring boot application?

The easiest way to prevent a Spring Boot application from starting an embedded web server is to not include the web server starter in our dependencies. This means not including the spring-boot-starter-web dependency in either the Maven POM or Gradle build file.


1 Answers

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

@SpringBootApplication(exclude = JmsAutoConfiguration.class) 
like image 96
dunni Avatar answered Sep 21 '22 04:09

dunni