mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Merge branch '1.2.x'
This commit is contained in:
commit
5cb9b9a9e9
@ -50,17 +50,15 @@ class ActiveMQConnectionFactoryConfiguration {
|
||||
@ConditionalOnClass(PooledConnectionFactory.class)
|
||||
static class PooledConnectionFactoryConfiguration {
|
||||
|
||||
@Bean
|
||||
@Bean(destroyMethod = "stop")
|
||||
@ConditionalOnProperty(prefix = "spring.activemq", name = "pooled", havingValue = "true", matchIfMissing = false)
|
||||
public PooledConnectionFactory pooledJmsConnectionFactory(
|
||||
ActiveMQProperties properties) {
|
||||
PooledConnectionFactory pooledConnectionFactory = new PooledConnectionFactory();
|
||||
pooledConnectionFactory
|
||||
.setConnectionFactory(new ActiveMQConnectionFactoryFactory(properties)
|
||||
return new PooledConnectionFactory(
|
||||
new ActiveMQConnectionFactoryFactory(properties)
|
||||
.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.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.jta.XAConnectionFactoryWrapper;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@ -53,15 +54,25 @@ class ActiveMQXAConnectionFactoryConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ConnectionFactory nonXaJmsConnectionFactory(ActiveMQProperties properties) {
|
||||
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactoryFactory(
|
||||
properties).createConnectionFactory(ActiveMQConnectionFactory.class);
|
||||
if (properties.isPooled()) {
|
||||
PooledConnectionFactory pool = new PooledConnectionFactory();
|
||||
pool.setConnectionFactory(connectionFactory);
|
||||
return pool;
|
||||
@ConditionalOnProperty(prefix = "spring.activemq", name = "pooled", havingValue = "false", matchIfMissing = true)
|
||||
public ActiveMQConnectionFactory nonXaJmsConnectionFactory(
|
||||
ActiveMQProperties properties) {
|
||||
return new ActiveMQConnectionFactoryFactory(properties)
|
||||
.createConnectionFactory(ActiveMQConnectionFactory.class);
|
||||
}
|
||||
|
||||
@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;
|
||||
|
||||
import javax.jms.ConnectionFactory;
|
||||
import javax.jms.JMSException;
|
||||
|
||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||
import org.apache.activemq.pool.PooledConnectionFactory;
|
||||
@ -29,6 +30,8 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
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.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
@ -62,11 +65,14 @@ public class ActiveMQAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pooledConnectionFactoryConfiguration() {
|
||||
public void pooledConnectionFactoryConfiguration() throws JMSException {
|
||||
load(EmptyConfiguration.class, "spring.activemq.pooled:true");
|
||||
ConnectionFactory connectionFactory = this.context
|
||||
.getBean(ConnectionFactory.class);
|
||||
assertThat(connectionFactory, instanceOf(PooledConnectionFactory.class));
|
||||
this.context.close();
|
||||
assertThat(((PooledConnectionFactory) connectionFactory).createConnection(),
|
||||
is(nullValue()));
|
||||
}
|
||||
|
||||
private void load(Class<?> config, String... environment) {
|
||||
|
Loading…
Reference in New Issue
Block a user