Tolerate breaking API changes in ActiveMQ 5.11.0

In ActiveMQ 5.11 the signature of
PooledConnectionFactory.setConnectionFactory has changed. It now takes
an Object rather than a ConnectionFactory. This change is not binary
backwards compatible so it causes a NoSuchMethodError as we compile
against 5.10.

This commit updates ActiveMQConnectionFactoryConfiguration to call
the setConnectionFactory method reflectively, looking for both the
ConnectionFactory and Object variants.

Closes gh-2640
This commit is contained in:
Andy Wilkinson
2015-03-16 17:41:38 +00:00
parent 78a00b1658
commit 1f40c8a9ba
2 changed files with 42 additions and 5 deletions

View File

@@ -19,8 +19,10 @@ package org.springframework.boot.autoconfigure.jms.activemq;
import javax.jms.ConnectionFactory;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.pool.PooledConnectionFactory;
import org.junit.Test;
import org.springframework.boot.autoconfigure.jms.JmsAutoConfiguration;
import org.springframework.boot.test.EnvironmentTestUtils;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -57,15 +59,25 @@ public class ActiveMQAutoConfigurationTests {
assertTrue(mockingDetails(this.context.getBean(ConnectionFactory.class)).isMock());
}
private void load(Class<?> config) {
this.context = doLoad(config);
@Test
public void pooledConnectionFactoryConfiguration() {
load(EmptyConfiguration.class, "spring.activemq.pooled:true");
ConnectionFactory connectionFactory = this.context
.getBean(ConnectionFactory.class);
assertThat(connectionFactory, instanceOf(PooledConnectionFactory.class));
}
private AnnotationConfigApplicationContext doLoad(Class<?> config) {
private void load(Class<?> config, String... environment) {
this.context = doLoad(config, environment);
}
private AnnotationConfigApplicationContext doLoad(Class<?> config,
String... environment) {
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
applicationContext.register(config);
applicationContext.register(ActiveMQAutoConfiguration.class,
JmsAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(applicationContext, environment);
applicationContext.refresh();
return applicationContext;
}