Merge branch '1.2.x'

pull/4753/merge
Andy Wilkinson 9 years ago
commit 5cb9b9a9e9

@ -50,17 +50,15 @@ class ActiveMQConnectionFactoryConfiguration {
@ConditionalOnClass(PooledConnectionFactory.class) @ConditionalOnClass(PooledConnectionFactory.class)
static class PooledConnectionFactoryConfiguration { static class PooledConnectionFactoryConfiguration {
@Bean @Bean(destroyMethod = "stop")
@ConditionalOnProperty(prefix = "spring.activemq", name = "pooled", havingValue = "true", matchIfMissing = false) @ConditionalOnProperty(prefix = "spring.activemq", name = "pooled", havingValue = "true", matchIfMissing = false)
public PooledConnectionFactory pooledJmsConnectionFactory( public PooledConnectionFactory pooledJmsConnectionFactory(
ActiveMQProperties properties) { ActiveMQProperties properties) {
PooledConnectionFactory pooledConnectionFactory = new PooledConnectionFactory(); return new PooledConnectionFactory(
pooledConnectionFactory new ActiveMQConnectionFactoryFactory(properties)
.setConnectionFactory(new ActiveMQConnectionFactoryFactory(properties)
.createConnectionFactory(ActiveMQConnectionFactory.class)); .createConnectionFactory(ActiveMQConnectionFactory.class));
return pooledConnectionFactory;
} }
} }
} }

@ -26,6 +26,7 @@ import org.apache.activemq.pool.PooledConnectionFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.jta.XAConnectionFactoryWrapper; import org.springframework.boot.jta.XAConnectionFactoryWrapper;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@ -53,15 +54,25 @@ class ActiveMQXAConnectionFactoryConfiguration {
} }
@Bean @Bean
public ConnectionFactory nonXaJmsConnectionFactory(ActiveMQProperties properties) { @ConditionalOnProperty(prefix = "spring.activemq", name = "pooled", havingValue = "false", matchIfMissing = true)
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactoryFactory( public ActiveMQConnectionFactory nonXaJmsConnectionFactory(
properties).createConnectionFactory(ActiveMQConnectionFactory.class); ActiveMQProperties properties) {
if (properties.isPooled()) { return new ActiveMQConnectionFactoryFactory(properties)
PooledConnectionFactory pool = new PooledConnectionFactory(); .createConnectionFactory(ActiveMQConnectionFactory.class);
pool.setConnectionFactory(connectionFactory); }
return pool;
@ConditionalOnClass(PooledConnectionFactory.class)
@ConditionalOnProperty(prefix = "spring.activemq", name = "pooled", havingValue = "true", matchIfMissing = false)
static class PooledConnectionFactoryConfiguration {
@Bean(destroyMethod = "stop")
public PooledConnectionFactory pooledNonXaJmsConnectionFactory(
ActiveMQProperties properties) {
return new PooledConnectionFactory(
new ActiveMQConnectionFactoryFactory(properties)
.createConnectionFactory(ActiveMQConnectionFactory.class));
} }
return connectionFactory;
} }
} }

@ -17,6 +17,7 @@
package org.springframework.boot.autoconfigure.jms.activemq; package org.springframework.boot.autoconfigure.jms.activemq;
import javax.jms.ConnectionFactory; import javax.jms.ConnectionFactory;
import javax.jms.JMSException;
import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.pool.PooledConnectionFactory; import org.apache.activemq.pool.PooledConnectionFactory;
@ -29,6 +30,8 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
@ -62,11 +65,14 @@ public class ActiveMQAutoConfigurationTests {
} }
@Test @Test
public void pooledConnectionFactoryConfiguration() { public void pooledConnectionFactoryConfiguration() throws JMSException {
load(EmptyConfiguration.class, "spring.activemq.pooled:true"); load(EmptyConfiguration.class, "spring.activemq.pooled:true");
ConnectionFactory connectionFactory = this.context ConnectionFactory connectionFactory = this.context
.getBean(ConnectionFactory.class); .getBean(ConnectionFactory.class);
assertThat(connectionFactory, instanceOf(PooledConnectionFactory.class)); assertThat(connectionFactory, instanceOf(PooledConnectionFactory.class));
this.context.close();
assertThat(((PooledConnectionFactory) connectionFactory).createConnection(),
is(nullValue()));
} }
private void load(Class<?> config, String... environment) { private void load(Class<?> config, String... environment) {

Loading…
Cancel
Save