添加事务支持
1 |
添加数据源配置
1 | #master |
加载配置
DataSourceConfig.java
1 | /** |
添加事务管理支持
DataSourceMasterManager.java
DataSourceSlaveManager.java1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58/**
* Created by xiehui1956(@)gmail.com on 2020/4/26
*/
"entityManagerFactoryMaster" (entityManagerFactoryRef =
, transactionManagerRef = "transactionManagerMaster"
, basePackages = {"com.dao"})
public class DataSourceMasterManager {
"masterDataSource") (
private DataSource masterDataSource;
"entityManagerFactoryMaster") (name =
public LocalContainerEntityManagerFactoryBean entityManagerFactoryBean(EntityManagerFactoryBuilder builder) {
return builder
.dataSource(masterDataSource)
.packages("com.entity")
.persistenceUnit("masterDataPersistenceUnit")
.build();
}
"transactionManagerMaster") (
public PlatformTransactionManager transactionManager(EntityManagerFactoryBuilder builder) {
return new JpaTransactionManager(entityManagerFactoryBean(builder).getObject());
}
}
/**
* Created by xiehui1956(@)gmail.com on 2020/4/26
*/
"entityManagerFactorySlave" (entityManagerFactoryRef =
, transactionManagerRef = "transactionManagerSlave"
, basePackages = {"com.dto"})
public class DataSourceSlaveManager {
"slaveDataSource") (
private DataSource slaveDataSource;
"entityManagerFactorySlave") (name =
public LocalContainerEntityManagerFactoryBean entityManagerFactoryBean(EntityManagerFactoryBuilder builder) {
return builder
.dataSource(slaveDataSource)
.packages("com.deo")
.persistenceUnit("slaveDataPersistenceUnit")
.build();
}
"transactionManagerSlave") (
public PlatformTransactionManager transactionManager(EntityManagerFactoryBuilder builder) {
return new JpaTransactionManager(entityManagerFactoryBean(builder).getObject());
}
}
使用
1 |
|