Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Autoconfiguration of ActiveMQ with spring integration

In current versions spring boot can also configure a ConnectionFactory when it detects that ActiveMQ is available on the classpath. If the broker is present, an embedded broker is started and configured automatically.

This seems to be true when using the JMSTemplate. If I want to use spring integration auto configuration then unfortunately this does not work. ActiveMQ seems to be configured AFTER spring integration. Spring boot reports error for missing connection factory. I am using spring boot version 1.1.4 and most current version of spring integration for this.

I get this stacktrace from spring boot:

2014-08-08 09:24:21.050 ERROR 6728 --- [           main]    
o.s.boot.SpringApplication               : Application startup failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 
'org.springframework.integration.jms.JmsSendingMessageHandler#0': 
Cannot create inner bean '(inner bean)#54930080' of type 
[org.springframework.integration.jms.DynamicJmsTemplate] while setting constructor 
argument; nested exception is org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name '(inner bean)#54930080': Cannot resolve reference to 
bean 'connectionFactory' while setting bean property 'connectionFactory'; nested 
exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean 
named 'connectionFactory' is defined
at 
org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(
BeanDefinitionValueResolver.java:290)
at   
org.springframework.beans.factory.support.BeanDefinitionValueResolver.
resolveValueIfNecessary(BeanDefinitionValueResolver.java:129)

For me it seems that the dependencies in spring boot auto configurations are not correct with respect of spring integration and jms template. Standard JMS auto configuration looks like the following:

@ConditionalOnClass(JmsTemplate.class)
@ConditionalOnBean(ConnectionFactory.class)
@EnableConfigurationProperties(JmsProperties.class)
@AutoConfigureAfter({ HornetQAutoConfiguration.class, 
ActiveMQAutoConfiguration.class })
public class JmsAutoConfiguration 

Spring integration looks like the following:

@Configuration
@ConditionalOnClass(EnableIntegration.class)
@AutoConfigureAfter(JmxAutoConfiguration.class)
public class IntegrationAutoConfiguration {

Shouldn't there be at least some kind of auto configuration for the dynamic jms template that spring integration creates regarding connection factory and active mq. Considering the spring boot ref docs I would expect correct auto configuration with jms for spring integration as well?

like image 834
Andreas Falk Avatar asked Nov 01 '22 19:11

Andreas Falk


1 Answers

Ok - got it. It's a bug (I think).

ActiveMQConnectionFactoryConfiguration creates a bean called "jmsConnectionFactory" but looking at your stacktrace (above) Spring Integration is looking for the bean to be named: 'connectionFactory'

Edit: INT-3941 opened

Workaround:

@Configuration
public static class SpringBootVsIntegraionWorkaround {
    @Autowired
    GenericApplicationContext genericApplicationContext;

    @PostConstruct
    public void init() {
        genericApplicationContext.registerAlias("jmsConnectionFactory", "connectionFactory");
    }
}
like image 172
Andy N Avatar answered Nov 11 '22 17:11

Andy N