Commit ff870de0 authored by Phillip Webb's avatar Phillip Webb

Fix a few JTA issues

- Search for ConnectionFactories in java:/JmsXA and
  java:/XAConnectionFactory
- Remove javax.transaction:jta managed dependency
- Removed unused JtaProperties argument

Fixes gh-947
parent 1024d5d4
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
package org.springframework.boot.autoconfigure.jms; package org.springframework.boot.autoconfigure.jms;
import java.util.Arrays;
import javax.jms.ConnectionFactory; import javax.jms.ConnectionFactory;
import javax.naming.NamingException; import javax.naming.NamingException;
...@@ -25,6 +27,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnJndi; ...@@ -25,6 +27,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnJndi;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.jndi.JndiLocatorDelegate; import org.springframework.jndi.JndiLocatorDelegate;
/** /**
...@@ -36,12 +39,26 @@ import org.springframework.jndi.JndiLocatorDelegate; ...@@ -36,12 +39,26 @@ import org.springframework.jndi.JndiLocatorDelegate;
@Configuration @Configuration
@AutoConfigureBefore(JmsAutoConfiguration.class) @AutoConfigureBefore(JmsAutoConfiguration.class)
@ConditionalOnMissingBean(ConnectionFactory.class) @ConditionalOnMissingBean(ConnectionFactory.class)
@ConditionalOnJndi("java:/JmsXA") @ConditionalOnJndi({ "java:/JmsXA", "java:/XAConnectionFactory" })
public class JndiConnectionFactoryAutoConfiguration { public class JndiConnectionFactoryAutoConfiguration {
@Bean @Bean
public ConnectionFactory connectionFactory() throws NamingException { public ConnectionFactory connectionFactory() throws NamingException {
return new JndiLocatorDelegate().lookup("java:/JmsXA", ConnectionFactory.class); for (String name : getJndiLocations()) {
try {
return new JndiLocatorDelegate().lookup(name, ConnectionFactory.class);
}
catch (NamingException ex) {
// Swallow and continue
}
}
throw new IllegalStateException(
"Unable to find ConnectionFactory in JNDI locations "
+ Arrays.asList(getJndiLocations()));
}
private String[] getJndiLocations() {
return AnnotationUtils.getAnnotation(getClass(), ConditionalOnJndi.class).value();
} }
} }
...@@ -57,7 +57,7 @@ class BitronixJtaConfiguration { ...@@ -57,7 +57,7 @@ class BitronixJtaConfiguration {
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
@ConfigurationProperties(prefix = JtaProperties.PREFIX) @ConfigurationProperties(prefix = JtaProperties.PREFIX)
public bitronix.tm.Configuration bitronixConfiguration(JtaProperties xxx) { public bitronix.tm.Configuration bitronixConfiguration() {
bitronix.tm.Configuration config = TransactionManagerServices.getConfiguration(); bitronix.tm.Configuration config = TransactionManagerServices.getConfiguration();
config.setServerId("spring-boot-jta-bitronix"); config.setServerId("spring-boot-jta-bitronix");
File logBaseDir = getLogBaseDir(); File logBaseDir = getLogBaseDir();
......
...@@ -88,7 +88,6 @@ ...@@ -88,7 +88,6 @@
<jolokia.version>1.2.2</jolokia.version> <jolokia.version>1.2.2</jolokia.version>
<json-path.version>0.9.1</json-path.version> <json-path.version>0.9.1</json-path.version>
<jstl.version>1.2</jstl.version> <jstl.version>1.2</jstl.version>
<jta.version>1.1</jta.version>
<junit.version>4.11</junit.version> <junit.version>4.11</junit.version>
<liquibase.version>3.0.8</liquibase.version> <liquibase.version>3.0.8</liquibase.version>
<log4j.version>1.2.17</log4j.version> <log4j.version>1.2.17</log4j.version>
...@@ -521,11 +520,6 @@ ...@@ -521,11 +520,6 @@
<artifactId>jstl</artifactId> <artifactId>jstl</artifactId>
<version>${jstl.version}</version> <version>${jstl.version}</version>
</dependency> </dependency>
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
<version>${jta.version}</version>
</dependency>
<dependency> <dependency>
<groupId>jaxen</groupId> <groupId>jaxen</groupId>
<artifactId>jaxen</artifactId> <artifactId>jaxen</artifactId>
......
...@@ -1929,8 +1929,9 @@ looking at common JNDI locations (`java:comp/UserTransaction`, ...@@ -1929,8 +1929,9 @@ looking at common JNDI locations (`java:comp/UserTransaction`,
`java:comp/TransactionManager` etc). If you are using a transaction service provided by `java:comp/TransactionManager` etc). If you are using a transaction service provided by
your application server, you will generally also want to ensure that all resources are your application server, you will generally also want to ensure that all resources are
managed by the server and exposed over JNDI. Spring Boot will attempt to auto-configure managed by the server and exposed over JNDI. Spring Boot will attempt to auto-configure
JMS by looking for a `ConnectionFactory` at the JNDI path `java:/JmsXA` and you can use JMS by looking for a `ConnectionFactory` at the JNDI path `java:/JmsXA` or
the <<boot-features-connecting-to-a-jndi-datasource, `spring.datasource.jndi-name` property>> `java:/XAConnectionFactory` and you can use the
<<boot-features-connecting-to-a-jndi-datasource, `spring.datasource.jndi-name` property>>
to configure your `DataSource`. to configure your `DataSource`.
......
...@@ -23,10 +23,6 @@ ...@@ -23,10 +23,6 @@
<groupId>javax.jms</groupId> <groupId>javax.jms</groupId>
<artifactId>jms-api</artifactId> <artifactId>jms-api</artifactId>
</dependency> </dependency>
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.codehaus.btm</groupId> <groupId>org.codehaus.btm</groupId>
<artifactId>btm</artifactId> <artifactId>btm</artifactId>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment