Permit to disable JTA using a single property
Disable JTA auto-configuration altogether with a simple property. This can be useful if the environment is JTA capable but the application does not require it. Fixes gh-1457
This commit is contained in:
parent
814803046a
commit
9dec27e7bf
|
|
@ -18,6 +18,7 @@ package org.springframework.boot.autoconfigure.jta;
|
|||
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
|
|
@ -29,6 +30,7 @@ import org.springframework.context.annotation.Import;
|
|||
* @since 1.2.0
|
||||
*/
|
||||
@ConditionalOnClass(javax.transaction.Transaction.class)
|
||||
@ConditionalOnProperty(prefix = "spring.jta", value = "enabled", matchIfMissing = true)
|
||||
@Import({ JndiJtaConfiguration.class, BitronixJtaConfiguration.class,
|
||||
AtomikosJtaConfiguration.class })
|
||||
@EnableConfigurationProperties(JtaProperties.class)
|
||||
|
|
|
|||
|
|
@ -59,6 +59,12 @@
|
|||
"description": "Automatically register OpenEntityManagerInViewInterceptor. Binds a JPA EntityManager to the thread for the entire processing of the request.",
|
||||
"defaultValue": true
|
||||
},
|
||||
{
|
||||
"name": "spring.jta.enabled",
|
||||
"dataType": "java.lang.Boolean",
|
||||
"description": "Enable JTA support.",
|
||||
"defaultValue": true
|
||||
},
|
||||
{
|
||||
"name": "spring.mobile.devicedelegatingviewresolver.enabled",
|
||||
"dataType": "java.lang.Boolean",
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ import com.atomikos.icatch.jta.UserTransactionManager;
|
|||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
|
@ -87,6 +88,18 @@ public class JtaAutoConfigurationTests {
|
|||
this.context.getBean(JtaTransactionManager.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void disableJtaSupport() {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
EnvironmentTestUtils.addEnvironment(this.context,
|
||||
"spring.jta.enabled:false");
|
||||
this.context.register(JtaAutoConfiguration.class);
|
||||
this.context.refresh();
|
||||
assertEquals(0, this.context.getBeansOfType(JtaTransactionManager.class).size());
|
||||
assertEquals(0, this.context.getBeansOfType(XADataSourceWrapper.class).size());
|
||||
assertEquals(0, this.context.getBeansOfType(XAConnectionFactoryWrapper.class).size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void atomikosSanityCheck() throws Exception {
|
||||
this.context = new AnnotationConfigApplicationContext(JtaProperties.class,
|
||||
|
|
|
|||
|
|
@ -2032,7 +2032,9 @@ transactions are also supported when deploying to a suitable Java EE Application
|
|||
When a JTA environment is detected, Spring's `JtaTransactionManager` will be used to manage
|
||||
transactions. Auto-configured JMS, DataSource and JPA beans will be upgraded to support
|
||||
XA transactions. You can use standard Spring idioms such as `@Transactional` to
|
||||
participate in a distributed transaction.
|
||||
participate in a distributed transaction. If you are within a JTA environment and still
|
||||
want to use local transactions you can set the `spring.jta.enabled` property to `false` to
|
||||
disable the JTA auto-configuration.
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue