Merge branch '2.7.x' into 3.0.x

Closes gh-36771
pull/37018/head
Stephane Nicoll 1 year ago
commit e7706b4201

@ -43,41 +43,40 @@ import org.springframework.jms.connection.CachingConnectionFactory;
class ArtemisConnectionFactoryConfiguration { class ArtemisConnectionFactoryConfiguration {
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)
@ConditionalOnClass(CachingConnectionFactory.class)
@ConditionalOnProperty(prefix = "spring.artemis.pool", name = "enabled", havingValue = "false", @ConditionalOnProperty(prefix = "spring.artemis.pool", name = "enabled", havingValue = "false",
matchIfMissing = true) matchIfMissing = true)
static class SimpleConnectionFactoryConfiguration { static class SimpleConnectionFactoryConfiguration {
private final ArtemisProperties properties; @Bean(name = "jmsConnectionFactory")
@ConditionalOnProperty(prefix = "spring.jms.cache", name = "enabled", havingValue = "false")
private final ListableBeanFactory beanFactory; ActiveMQConnectionFactory jmsConnectionFactory(ArtemisProperties properties, ListableBeanFactory beanFactory) {
return createJmsConnectionFactory(properties, beanFactory);
}
SimpleConnectionFactoryConfiguration(ArtemisProperties properties, ListableBeanFactory beanFactory) { private static ActiveMQConnectionFactory createJmsConnectionFactory(ArtemisProperties properties,
this.properties = properties; ListableBeanFactory beanFactory) {
this.beanFactory = beanFactory; return new ArtemisConnectionFactoryFactory(beanFactory, properties)
.createConnectionFactory(ActiveMQConnectionFactory.class);
} }
@Bean(name = "jmsConnectionFactory") @Configuration(proxyBeanMethods = false)
@ConditionalOnClass(CachingConnectionFactory.class)
@ConditionalOnProperty(prefix = "spring.jms.cache", name = "enabled", havingValue = "true", @ConditionalOnProperty(prefix = "spring.jms.cache", name = "enabled", havingValue = "true",
matchIfMissing = true) matchIfMissing = true)
CachingConnectionFactory cachingJmsConnectionFactory(JmsProperties jmsProperties) { static class CachingConnectionFactoryConfiguration {
JmsProperties.Cache cacheProperties = jmsProperties.getCache();
CachingConnectionFactory connectionFactory = new CachingConnectionFactory(createConnectionFactory()); @Bean(name = "jmsConnectionFactory")
connectionFactory.setCacheConsumers(cacheProperties.isConsumers()); CachingConnectionFactory cachingJmsConnectionFactory(JmsProperties jmsProperties,
connectionFactory.setCacheProducers(cacheProperties.isProducers()); ArtemisProperties properties, ListableBeanFactory beanFactory) {
connectionFactory.setSessionCacheSize(cacheProperties.getSessionCacheSize()); JmsProperties.Cache cacheProperties = jmsProperties.getCache();
return connectionFactory; CachingConnectionFactory connectionFactory = new CachingConnectionFactory(
} createJmsConnectionFactory(properties, beanFactory));
connectionFactory.setCacheConsumers(cacheProperties.isConsumers());
@Bean(name = "jmsConnectionFactory") connectionFactory.setCacheProducers(cacheProperties.isProducers());
@ConditionalOnProperty(prefix = "spring.jms.cache", name = "enabled", havingValue = "false") connectionFactory.setSessionCacheSize(cacheProperties.getSessionCacheSize());
ActiveMQConnectionFactory jmsConnectionFactory() { return connectionFactory;
return createConnectionFactory(); }
}
private ActiveMQConnectionFactory createConnectionFactory() {
return new ArtemisConnectionFactoryFactory(this.beanFactory, this.properties)
.createConnectionFactory(ActiveMQConnectionFactory.class);
} }
} }

@ -46,6 +46,7 @@ import org.messaginghub.pooled.jms.JmsPoolConnectionFactory;
import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.jms.JmsAutoConfiguration; import org.springframework.boot.autoconfigure.jms.JmsAutoConfiguration;
import org.springframework.boot.test.context.FilteredClassLoader;
import org.springframework.boot.test.context.assertj.AssertableApplicationContext; import org.springframework.boot.test.context.assertj.AssertableApplicationContext;
import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
@ -356,6 +357,20 @@ class ArtemisAutoConfigurationTests {
}); });
} }
@Test
void cachingConnectionFactoryNotOnTheClasspathThenSimpleConnectionFactoryAutoConfigured() {
this.contextRunner.withClassLoader(new FilteredClassLoader(CachingConnectionFactory.class))
.withPropertyValues("spring.artemis.pool.enabled=false", "spring.jms.cache.enabled=false")
.run((context) -> assertThat(context).hasSingleBean(ActiveMQConnectionFactory.class));
}
@Test
void cachingConnectionFactoryNotOnTheClasspathAndCacheEnabledThenSimpleConnectionFactoryNotConfigured() {
this.contextRunner.withClassLoader(new FilteredClassLoader(CachingConnectionFactory.class))
.withPropertyValues("spring.artemis.pool.enabled=false", "spring.jms.cache.enabled=true")
.run((context) -> assertThat(context).doesNotHaveBean(ActiveMQConnectionFactory.class));
}
private ConnectionFactory getConnectionFactory(AssertableApplicationContext context) { private ConnectionFactory getConnectionFactory(AssertableApplicationContext context) {
assertThat(context).hasSingleBean(ConnectionFactory.class).hasBean("jmsConnectionFactory"); assertThat(context).hasSingleBean(ConnectionFactory.class).hasBean("jmsConnectionFactory");
ConnectionFactory connectionFactory = context.getBean(ConnectionFactory.class); ConnectionFactory connectionFactory = context.getBean(ConnectionFactory.class);

Loading…
Cancel
Save