Inject any existing JMS DestinationResolver bean

Update JmsAutoConfiguration to inject any existing DestinationResolver
bean into JmsTemplate and DefaultJmsListenerContainerFactory.

Fixes gh-1443
pull/1442/merge
Phillip Webb 10 years ago
parent 7a5248e38c
commit 5b9d45b231

@ -31,6 +31,7 @@ import org.springframework.jms.annotation.JmsListenerAnnotationBeanPostProcessor
import org.springframework.jms.config.DefaultJmsListenerContainerFactory; import org.springframework.jms.config.DefaultJmsListenerContainerFactory;
import org.springframework.jms.core.JmsMessagingTemplate; import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.jms.core.JmsTemplate; import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.support.destination.DestinationResolver;
/** /**
* {@link EnableAutoConfiguration Auto-configuration} for Spring JMS. * {@link EnableAutoConfiguration Auto-configuration} for Spring JMS.
@ -50,11 +51,17 @@ public class JmsAutoConfiguration {
@Autowired @Autowired
private ConnectionFactory connectionFactory; private ConnectionFactory connectionFactory;
@Autowired(required = false)
private DestinationResolver destinationResolver;
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
public JmsTemplate jmsTemplate() { public JmsTemplate jmsTemplate() {
JmsTemplate jmsTemplate = new JmsTemplate(this.connectionFactory); JmsTemplate jmsTemplate = new JmsTemplate(this.connectionFactory);
jmsTemplate.setPubSubDomain(this.properties.isPubSubDomain()); jmsTemplate.setPubSubDomain(this.properties.isPubSubDomain());
if (this.destinationResolver != null) {
jmsTemplate.setDestinationResolver(this.destinationResolver);
}
return jmsTemplate; return jmsTemplate;
} }
@ -73,12 +80,18 @@ public class JmsAutoConfiguration {
@ConditionalOnBean(JmsListenerAnnotationBeanPostProcessor.class) @ConditionalOnBean(JmsListenerAnnotationBeanPostProcessor.class)
protected static class AnnotationDrivenConfiguration { protected static class AnnotationDrivenConfiguration {
@ConditionalOnMissingBean(name = "jmsListenerContainerFactory") @Autowired(required = false)
private DestinationResolver destinationResolver;
@Bean @Bean
@ConditionalOnMissingBean(name = "jmsListenerContainerFactory")
public DefaultJmsListenerContainerFactory jmsListenerContainerFactory( public DefaultJmsListenerContainerFactory jmsListenerContainerFactory(
ConnectionFactory connectionFactory) { ConnectionFactory connectionFactory) {
DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory(); DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
factory.setConnectionFactory(connectionFactory); factory.setConnectionFactory(connectionFactory);
if (this.destinationResolver != null) {
factory.setDestinationResolver(this.destinationResolver);
}
return factory; return factory;
} }

Loading…
Cancel
Save