Add TransactionTemplate auto-configuration
Provide a TransactionTemplate if one PlatformTransactionManager is present. Relocated the jta support as a nested package of the new transaction package that hosts the transaction template auto-configuration. To avoid package tangles, links between auto-configurations have been reversed. Closes gh-2464 Closes gh-2809
This commit is contained in:
parent
cee8c5c1c3
commit
578bd5dc37
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2014 the original author or authors.
|
* Copyright 2012-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -24,13 +24,11 @@ import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.MutablePropertyValues;
|
import org.springframework.beans.MutablePropertyValues;
|
||||||
import org.springframework.beans.factory.BeanClassLoaderAware;
|
import org.springframework.beans.factory.BeanClassLoaderAware;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
import org.springframework.boot.autoconfigure.jta.JtaAutoConfiguration;
|
|
||||||
import org.springframework.boot.bind.RelaxedDataBinder;
|
import org.springframework.boot.bind.RelaxedDataBinder;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
|
|
@ -49,7 +47,6 @@ import org.springframework.util.StringUtils;
|
||||||
* @since 1.2.0
|
* @since 1.2.0
|
||||||
*/
|
*/
|
||||||
@AutoConfigureBefore(DataSourceAutoConfiguration.class)
|
@AutoConfigureBefore(DataSourceAutoConfiguration.class)
|
||||||
@AutoConfigureAfter(JtaAutoConfiguration.class)
|
|
||||||
@EnableConfigurationProperties(DataSourceProperties.class)
|
@EnableConfigurationProperties(DataSourceProperties.class)
|
||||||
@ConditionalOnClass({ DataSource.class, TransactionManager.class,
|
@ConditionalOnClass({ DataSource.class, TransactionManager.class,
|
||||||
EmbeddedDatabaseType.class })
|
EmbeddedDatabaseType.class })
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2014 the original author or authors.
|
* Copyright 2012-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -26,7 +26,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
import org.springframework.boot.autoconfigure.jms.JmsAutoConfiguration;
|
import org.springframework.boot.autoconfigure.jms.JmsAutoConfiguration;
|
||||||
import org.springframework.boot.autoconfigure.jms.JndiConnectionFactoryAutoConfiguration;
|
import org.springframework.boot.autoconfigure.jms.JndiConnectionFactoryAutoConfiguration;
|
||||||
import org.springframework.boot.autoconfigure.jta.JtaAutoConfiguration;
|
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
|
|
@ -42,8 +41,7 @@ import org.springframework.context.annotation.Import;
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
@AutoConfigureBefore(JmsAutoConfiguration.class)
|
@AutoConfigureBefore(JmsAutoConfiguration.class)
|
||||||
@AutoConfigureAfter({ JtaAutoConfiguration.class,
|
@AutoConfigureAfter({ JndiConnectionFactoryAutoConfiguration.class })
|
||||||
JndiConnectionFactoryAutoConfiguration.class })
|
|
||||||
@ConditionalOnClass({ ConnectionFactory.class, ActiveMQConnectionFactory.class })
|
@ConditionalOnClass({ ConnectionFactory.class, ActiveMQConnectionFactory.class })
|
||||||
@ConditionalOnMissingBean(ConnectionFactory.class)
|
@ConditionalOnMissingBean(ConnectionFactory.class)
|
||||||
@EnableConfigurationProperties(ActiveMQProperties.class)
|
@EnableConfigurationProperties(ActiveMQProperties.class)
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2014 the original author or authors.
|
* Copyright 2012-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -26,7 +26,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
import org.springframework.boot.autoconfigure.jms.JmsAutoConfiguration;
|
import org.springframework.boot.autoconfigure.jms.JmsAutoConfiguration;
|
||||||
import org.springframework.boot.autoconfigure.jms.JndiConnectionFactoryAutoConfiguration;
|
import org.springframework.boot.autoconfigure.jms.JndiConnectionFactoryAutoConfiguration;
|
||||||
import org.springframework.boot.autoconfigure.jta.JtaAutoConfiguration;
|
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
|
|
@ -44,8 +43,7 @@ import org.springframework.context.annotation.Import;
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
@AutoConfigureBefore(JmsAutoConfiguration.class)
|
@AutoConfigureBefore(JmsAutoConfiguration.class)
|
||||||
@AutoConfigureAfter({ JtaAutoConfiguration.class,
|
@AutoConfigureAfter({ JndiConnectionFactoryAutoConfiguration.class })
|
||||||
JndiConnectionFactoryAutoConfiguration.class })
|
|
||||||
@ConditionalOnClass({ ConnectionFactory.class, HornetQJMSClient.class })
|
@ConditionalOnClass({ ConnectionFactory.class, HornetQJMSClient.class })
|
||||||
@ConditionalOnMissingBean(ConnectionFactory.class)
|
@ConditionalOnMissingBean(ConnectionFactory.class)
|
||||||
@EnableConfigurationProperties(HornetQProperties.class)
|
@EnableConfigurationProperties(HornetQProperties.class)
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||||
import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
|
import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
|
||||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||||
import org.springframework.boot.autoconfigure.jta.JtaAutoConfiguration;
|
|
||||||
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration.HibernateEntityManagerCondition;
|
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration.HibernateEntityManagerCondition;
|
||||||
import org.springframework.boot.orm.jpa.hibernate.SpringJtaPlatform;
|
import org.springframework.boot.orm.jpa.hibernate.SpringJtaPlatform;
|
||||||
import org.springframework.context.annotation.ConditionContext;
|
import org.springframework.context.annotation.ConditionContext;
|
||||||
|
|
@ -59,7 +58,7 @@ import org.springframework.util.ClassUtils;
|
||||||
@ConditionalOnClass({ LocalContainerEntityManagerFactoryBean.class,
|
@ConditionalOnClass({ LocalContainerEntityManagerFactoryBean.class,
|
||||||
EnableTransactionManagement.class, EntityManager.class })
|
EnableTransactionManagement.class, EntityManager.class })
|
||||||
@Conditional(HibernateEntityManagerCondition.class)
|
@Conditional(HibernateEntityManagerCondition.class)
|
||||||
@AutoConfigureAfter({ DataSourceAutoConfiguration.class, JtaAutoConfiguration.class })
|
@AutoConfigureAfter({ DataSourceAutoConfiguration.class })
|
||||||
public class HibernateJpaAutoConfiguration extends JpaBaseConfiguration {
|
public class HibernateJpaAutoConfiguration extends JpaBaseConfiguration {
|
||||||
|
|
||||||
private static final Log logger = LogFactory
|
private static final Log logger = LogFactory
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,55 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2012-2015 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.boot.autoconfigure.transaction;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate;
|
||||||
|
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
|
||||||
|
import org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration;
|
||||||
|
import org.springframework.boot.autoconfigure.transaction.jta.JtaAutoConfiguration;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.transaction.PlatformTransactionManager;
|
||||||
|
import org.springframework.transaction.support.TransactionTemplate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link org.springframework.boot.autoconfigure.EnableAutoConfiguration
|
||||||
|
* Auto-configuration} for Spring transaction.
|
||||||
|
*
|
||||||
|
* @author Stephane Nicoll
|
||||||
|
* @since 1.3.0
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
@ConditionalOnClass({ TransactionTemplate.class, PlatformTransactionManager.class })
|
||||||
|
@ConditionalOnSingleCandidate(PlatformTransactionManager.class)
|
||||||
|
@AutoConfigureAfter({ JtaAutoConfiguration.class, JpaBaseConfiguration.class,
|
||||||
|
DataSourceTransactionManagerAutoConfiguration.class })
|
||||||
|
public class TransactionAutoConfiguration {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private PlatformTransactionManager transactionManager;
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnMissingBean
|
||||||
|
public TransactionTemplate transactionTemplate() {
|
||||||
|
return new TransactionTemplate(this.transactionManager);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2014 the original author or authors.
|
* Copyright 2012-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.boot.autoconfigure.jta;
|
package org.springframework.boot.autoconfigure.transaction.jta;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2014 the original author or authors.
|
* Copyright 2012-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.boot.autoconfigure.jta;
|
package org.springframework.boot.autoconfigure.transaction.jta;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2014 the original author or authors.
|
* Copyright 2012-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.boot.autoconfigure.jta;
|
package org.springframework.boot.autoconfigure.transaction.jta;
|
||||||
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnJndi;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnJndi;
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2014 the original author or authors.
|
* Copyright 2012-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -14,11 +14,16 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.boot.autoconfigure.jta;
|
package org.springframework.boot.autoconfigure.transaction.jta;
|
||||||
|
|
||||||
|
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
|
import org.springframework.boot.autoconfigure.jdbc.XADataSourceAutoConfiguration;
|
||||||
|
import org.springframework.boot.autoconfigure.jms.activemq.ActiveMQAutoConfiguration;
|
||||||
|
import org.springframework.boot.autoconfigure.jms.hornetq.HornetQAutoConfiguration;
|
||||||
|
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
|
|
||||||
|
|
@ -31,6 +36,9 @@ import org.springframework.context.annotation.Import;
|
||||||
*/
|
*/
|
||||||
@ConditionalOnClass(javax.transaction.Transaction.class)
|
@ConditionalOnClass(javax.transaction.Transaction.class)
|
||||||
@ConditionalOnProperty(prefix = "spring.jta", value = "enabled", matchIfMissing = true)
|
@ConditionalOnProperty(prefix = "spring.jta", value = "enabled", matchIfMissing = true)
|
||||||
|
@AutoConfigureBefore({ XADataSourceAutoConfiguration.class,
|
||||||
|
ActiveMQAutoConfiguration.class, HornetQAutoConfiguration.class,
|
||||||
|
HibernateJpaAutoConfiguration.class })
|
||||||
@Import({ JndiJtaConfiguration.class, BitronixJtaConfiguration.class,
|
@Import({ JndiJtaConfiguration.class, BitronixJtaConfiguration.class,
|
||||||
AtomikosJtaConfiguration.class })
|
AtomikosJtaConfiguration.class })
|
||||||
@EnableConfigurationProperties(JtaProperties.class)
|
@EnableConfigurationProperties(JtaProperties.class)
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2014 the original author or authors.
|
* Copyright 2012-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.boot.autoconfigure.jta;
|
package org.springframework.boot.autoconfigure.transaction.jta;
|
||||||
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
import org.springframework.transaction.jta.JtaTransactionManager;
|
import org.springframework.transaction.jta.JtaTransactionManager;
|
||||||
|
|
@ -17,5 +17,5 @@
|
||||||
/**
|
/**
|
||||||
* Auto-configuration for JTA.
|
* Auto-configuration for JTA.
|
||||||
*/
|
*/
|
||||||
package org.springframework.boot.autoconfigure.jta;
|
package org.springframework.boot.autoconfigure.transaction.jta;
|
||||||
|
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2012-2015 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Auto-configuration for transaction suport.
|
||||||
|
*/
|
||||||
|
package org.springframework.boot.autoconfigure.transaction;
|
||||||
|
|
@ -32,7 +32,6 @@ org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration,\
|
||||||
org.springframework.boot.autoconfigure.jms.JndiConnectionFactoryAutoConfiguration,\
|
org.springframework.boot.autoconfigure.jms.JndiConnectionFactoryAutoConfiguration,\
|
||||||
org.springframework.boot.autoconfigure.jms.activemq.ActiveMQAutoConfiguration,\
|
org.springframework.boot.autoconfigure.jms.activemq.ActiveMQAutoConfiguration,\
|
||||||
org.springframework.boot.autoconfigure.jms.hornetq.HornetQAutoConfiguration,\
|
org.springframework.boot.autoconfigure.jms.hornetq.HornetQAutoConfiguration,\
|
||||||
org.springframework.boot.autoconfigure.jta.JtaAutoConfiguration,\
|
|
||||||
org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchAutoConfiguration,\
|
org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchAutoConfiguration,\
|
||||||
org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchDataAutoConfiguration,\
|
org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchDataAutoConfiguration,\
|
||||||
org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration,\
|
org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration,\
|
||||||
|
|
@ -59,6 +58,8 @@ org.springframework.boot.autoconfigure.social.TwitterAutoConfiguration,\
|
||||||
org.springframework.boot.autoconfigure.solr.SolrAutoConfiguration,\
|
org.springframework.boot.autoconfigure.solr.SolrAutoConfiguration,\
|
||||||
org.springframework.boot.autoconfigure.velocity.VelocityAutoConfiguration,\
|
org.springframework.boot.autoconfigure.velocity.VelocityAutoConfiguration,\
|
||||||
org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration,\
|
org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration,\
|
||||||
|
org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration,\
|
||||||
|
org.springframework.boot.autoconfigure.transaction.jta.JtaAutoConfiguration,\
|
||||||
org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration,\
|
org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration,\
|
||||||
org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration,\
|
org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration,\
|
||||||
org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration,\
|
org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration,\
|
||||||
|
|
|
||||||
|
|
@ -29,9 +29,9 @@ import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.beans.factory.BeanCreationException;
|
import org.springframework.beans.factory.BeanCreationException;
|
||||||
import org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration;
|
import org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration;
|
||||||
import org.springframework.boot.autoconfigure.jta.JtaAutoConfiguration;
|
|
||||||
import org.springframework.boot.autoconfigure.jta.JtaProperties;
|
|
||||||
import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration;
|
import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration;
|
||||||
|
import org.springframework.boot.autoconfigure.transaction.jta.JtaAutoConfiguration;
|
||||||
|
import org.springframework.boot.autoconfigure.transaction.jta.JtaProperties;
|
||||||
import org.springframework.boot.orm.jpa.hibernate.SpringJtaPlatform;
|
import org.springframework.boot.orm.jpa.hibernate.SpringJtaPlatform;
|
||||||
import org.springframework.boot.test.EnvironmentTestUtils;
|
import org.springframework.boot.test.EnvironmentTestUtils;
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,125 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2012-2015 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.boot.autoconfigure.transaction;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||||
|
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
|
||||||
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.transaction.PlatformTransactionManager;
|
||||||
|
import org.springframework.transaction.support.TransactionTemplate;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertSame;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for {@link TransactionAutoConfiguration}.
|
||||||
|
*
|
||||||
|
* @author Stephane Nicoll
|
||||||
|
*/
|
||||||
|
public class TransactionAutoConfigurationTests {
|
||||||
|
|
||||||
|
private AnnotationConfigApplicationContext context;
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown() {
|
||||||
|
if (this.context != null) {
|
||||||
|
this.context.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void noTransactionManager() {
|
||||||
|
load(EmptyConfiguration.class);
|
||||||
|
assertEquals(0, this.context.getBeansOfType(TransactionTemplate.class).size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void singleTransactionManager() {
|
||||||
|
load(DataSourceAutoConfiguration.class,
|
||||||
|
DataSourceTransactionManagerAutoConfiguration.class);
|
||||||
|
PlatformTransactionManager transactionManager = this.context
|
||||||
|
.getBean(PlatformTransactionManager.class);
|
||||||
|
TransactionTemplate transactionTemplate = this.context
|
||||||
|
.getBean(TransactionTemplate.class);
|
||||||
|
assertSame(transactionManager, transactionTemplate.getTransactionManager());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void severalTransactionManagers() {
|
||||||
|
load(SeveralTransactionManagersConfiguration.class);
|
||||||
|
assertEquals(0, this.context.getBeansOfType(TransactionTemplate.class).size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void customTransactionManager() {
|
||||||
|
load(CustomTransactionManagerConfiguration.class);
|
||||||
|
Map<String, TransactionTemplate> beans = this.context
|
||||||
|
.getBeansOfType(TransactionTemplate.class);
|
||||||
|
assertEquals(1, beans.size());
|
||||||
|
assertTrue(beans.containsKey("transactionTemplateFoo"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void load(Class<?>... configs) {
|
||||||
|
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
|
||||||
|
applicationContext.register(configs);
|
||||||
|
applicationContext.register(TransactionAutoConfiguration.class);
|
||||||
|
applicationContext.refresh();
|
||||||
|
this.context = applicationContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
static class EmptyConfiguration {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
static class SeveralTransactionManagersConfiguration {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public PlatformTransactionManager transactionManagerOne() {
|
||||||
|
return mock(PlatformTransactionManager.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public PlatformTransactionManager transactionManagerTwo() {
|
||||||
|
return mock(PlatformTransactionManager.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
static class CustomTransactionManagerConfiguration {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public TransactionTemplate transactionTemplateFoo() {
|
||||||
|
return new TransactionTemplate(transactionManagerFoo());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public PlatformTransactionManager transactionManagerFoo() {
|
||||||
|
return mock(PlatformTransactionManager.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.boot.autoconfigure.jta;
|
package org.springframework.boot.autoconfigure.transaction.jta;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
Loading…
Reference in New Issue