From ff870de0f0bc96d3e82a78560c030100b7ff9385 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 27 Aug 2014 09:24:45 -0700 Subject: [PATCH] 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 --- ...ndiConnectionFactoryAutoConfiguration.java | 21 +++++++++++++++++-- .../jta/BitronixJtaConfiguration.java | 2 +- spring-boot-dependencies/pom.xml | 6 ------ .../main/asciidoc/spring-boot-features.adoc | 5 +++-- .../spring-boot-starter-jta-bitronix/pom.xml | 4 ---- 5 files changed, 23 insertions(+), 15 deletions(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/JndiConnectionFactoryAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/JndiConnectionFactoryAutoConfiguration.java index 9bb79bc3898..7244eb09efb 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/JndiConnectionFactoryAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/JndiConnectionFactoryAutoConfiguration.java @@ -16,6 +16,8 @@ package org.springframework.boot.autoconfigure.jms; +import java.util.Arrays; + import javax.jms.ConnectionFactory; import javax.naming.NamingException; @@ -25,6 +27,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnJndi; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.core.annotation.AnnotationUtils; import org.springframework.jndi.JndiLocatorDelegate; /** @@ -36,12 +39,26 @@ import org.springframework.jndi.JndiLocatorDelegate; @Configuration @AutoConfigureBefore(JmsAutoConfiguration.class) @ConditionalOnMissingBean(ConnectionFactory.class) -@ConditionalOnJndi("java:/JmsXA") +@ConditionalOnJndi({ "java:/JmsXA", "java:/XAConnectionFactory" }) public class JndiConnectionFactoryAutoConfiguration { @Bean 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(); } } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jta/BitronixJtaConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jta/BitronixJtaConfiguration.java index 6a3407a5e49..eff02e143a1 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jta/BitronixJtaConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jta/BitronixJtaConfiguration.java @@ -57,7 +57,7 @@ class BitronixJtaConfiguration { @Bean @ConditionalOnMissingBean @ConfigurationProperties(prefix = JtaProperties.PREFIX) - public bitronix.tm.Configuration bitronixConfiguration(JtaProperties xxx) { + public bitronix.tm.Configuration bitronixConfiguration() { bitronix.tm.Configuration config = TransactionManagerServices.getConfiguration(); config.setServerId("spring-boot-jta-bitronix"); File logBaseDir = getLogBaseDir(); diff --git a/spring-boot-dependencies/pom.xml b/spring-boot-dependencies/pom.xml index 18be92c8c1a..3dc77dd1b4e 100644 --- a/spring-boot-dependencies/pom.xml +++ b/spring-boot-dependencies/pom.xml @@ -88,7 +88,6 @@ 1.2.2 0.9.1 1.2 - 1.1 4.11 3.0.8 1.2.17 @@ -521,11 +520,6 @@ jstl ${jstl.version} - - javax.transaction - jta - ${jta.version} - jaxen jaxen diff --git a/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc b/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc index e79ad9b97a3..39fe27b13f4 100644 --- a/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc +++ b/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc @@ -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 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 -JMS by looking for a `ConnectionFactory` at the JNDI path `java:/JmsXA` and you can use -the <> +JMS by looking for a `ConnectionFactory` at the JNDI path `java:/JmsXA` or +`java:/XAConnectionFactory` and you can use the +<> to configure your `DataSource`. diff --git a/spring-boot-starters/spring-boot-starter-jta-bitronix/pom.xml b/spring-boot-starters/spring-boot-starter-jta-bitronix/pom.xml index ced6f76870b..024f9e404d4 100644 --- a/spring-boot-starters/spring-boot-starter-jta-bitronix/pom.xml +++ b/spring-boot-starters/spring-boot-starter-jta-bitronix/pom.xml @@ -23,10 +23,6 @@ javax.jms jms-api - - javax.transaction - jta - org.codehaus.btm btm