mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-09-03 04:26:12 +08:00
Allow @EnableTransactionManagement to be supplied by user
This commit is contained in:
parent
e7675a0630
commit
07da034571
@ -23,12 +23,15 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.annotation.AbstractTransactionManagementConfiguration;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
/**
|
||||
* {@link EnableAutoConfiguration Auto-configuration} for
|
||||
@ -55,4 +58,11 @@ public class DataSourceTransactionManagerAutoConfiguration implements Ordered {
|
||||
return new DataSourceTransactionManager(this.dataSource);
|
||||
}
|
||||
|
||||
@ConditionalOnMissingClass(AbstractTransactionManagementConfiguration.class)
|
||||
@Configuration
|
||||
@EnableTransactionManagement
|
||||
protected static class TransactionManagementConfiguration {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -48,7 +48,6 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
EnableTransactionManagement.class, EntityManager.class,
|
||||
HibernateEntityManager.class })
|
||||
@ConditionalOnBean(DataSource.class)
|
||||
@EnableTransactionManagement
|
||||
@AutoConfigureAfter(DataSourceAutoConfiguration.class)
|
||||
public class HibernateJpaAutoConfiguration extends JpaBaseConfiguration implements
|
||||
BeanClassLoaderAware {
|
||||
|
@ -139,4 +139,5 @@ public abstract class JpaBaseConfiguration implements BeanFactoryAware, Environm
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,10 +19,9 @@ package org.springframework.boot.autoconfigure.jdbc;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
@ -55,4 +54,19 @@ public class DataSourceTransactionManagerAutoConfigurationTests {
|
||||
this.context.getBeanNamesForType(DataSourceTransactionManager.class).length);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testManualConfiguration() throws Exception {
|
||||
this.context.register(SwitchTransactionsOn.class,
|
||||
EmbeddedDataSourceConfiguration.class,
|
||||
DataSourceTransactionManagerAutoConfiguration.class);
|
||||
this.context.refresh();
|
||||
assertNotNull(this.context.getBean(DataSource.class));
|
||||
assertNotNull(this.context.getBean(DataSourceTransactionManager.class));
|
||||
}
|
||||
|
||||
@EnableTransactionManagement
|
||||
protected static class SwitchTransactionsOn {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user