Skip to content

Commit c84c915

Browse files
author
Xiong Neng
committed
完成springboot-multisource升级重构
1 parent 62a79fa commit c84c915

File tree

4 files changed

+11
-34
lines changed

4 files changed

+11
-34
lines changed

springboot-multisource/src/main/java/com/xncoding/pos/service/UserService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.xncoding.pos.common.dao.repository.UserMapper;
66
import com.xncoding.pos.common.mutidatesource.DSEnum;
77
import org.springframework.stereotype.Service;
8+
import org.springframework.transaction.annotation.Transactional;
89

910
import javax.annotation.Resource;
1011

@@ -13,6 +14,7 @@
1314
*/
1415

1516
@Service
17+
@Transactional
1618
public class UserService {
1719

1820
@Resource

springboot-multisource/src/main/resources/application.yml

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ logging:
3838
spring:
3939
profiles: dev
4040
datasource:
41-
url: jdbc:mysql://127.0.0.1:3306/pos?useSSL=false&autoReconnect=true&tinyInt1isBit=false&useUnicode=true&characterEncoding=utf8
41+
url: jdbc:mysql://127.0.0.1:3306/pos?serverTimezone=UTC&useSSL=false&autoReconnect=true&tinyInt1isBit=false&useUnicode=true&characterEncoding=utf8
4242
username: root
4343
password: 123456
4444

4545
#多数据源
4646
biz:
4747
datasource:
48-
url: jdbc:mysql://127.0.0.1:3306/biz?useSSL=false&autoReconnect=true&tinyInt1isBit=false&useUnicode=true&characterEncoding=utf8
48+
url: jdbc:mysql://127.0.0.1:3306/biz?serverTimezone=UTC&useSSL=false&autoReconnect=true&tinyInt1isBit=false&useUnicode=true&characterEncoding=utf8
4949
username: root
5050
password: 123456
5151

@@ -54,31 +54,5 @@ logging:
5454
ROOT: INFO
5555
com:
5656
xncoding: DEBUG
57-
file: E:/logs/app.log
57+
file: D:/logs/app.log
5858

59-
---
60-
61-
#####################################################################
62-
######################## 测试环境profile ##########################
63-
#####################################################################
64-
65-
spring:
66-
profiles: test
67-
datasource:
68-
url: jdbc:mysql://127.0.0.1:3306/pos?useSSL=false&autoReconnect=true&tinyInt1isBit=false&useUnicode=true&characterEncoding=utf8
69-
username: root
70-
password: 123456
71-
72-
#多数据源
73-
biz:
74-
datasource:
75-
url: jdbc:mysql://127.0.0.1:3306/biz?useSSL=false&autoReconnect=true&tinyInt1isBit=false&useUnicode=true&characterEncoding=utf8
76-
username: root
77-
password: 123456
78-
79-
logging:
80-
level:
81-
ROOT: INFO
82-
com:
83-
xncoding: DEBUG
84-
file: /var/logs/app.log

springboot-multisource/src/main/resources/sql/schema.sql

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# -------------------------------------以下是pos业务库开始-------------------------------------------
1+
-- -------------------------------------以下是pos业务库开始-------------------------------------------
22
CREATE DATABASE IF NOT EXISTS pos default charset utf8 COLLATE utf8_general_ci;
33
SET FOREIGN_KEY_CHECKS=0;
44
USE pos;
@@ -18,13 +18,13 @@ CREATE TABLE `t_user` (
1818
`updated_time` DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间'
1919
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='后台管理用户表';
2020

21-
# 下面是pos数据库中的插入数据
21+
-- 下面是pos数据库中的插入数据
2222
INSERT INTO `t_user` VALUES (1,'admin','系统管理员','123456','www', '17890908889', '系统管理员', 1, '2017-12-12 09:46:12', '2017-12-12 09:46:12');
2323
INSERT INTO `t_user` VALUES (2,'aix','张三','123456','eee', '17859569358', '', 1, '2017-12-12 09:46:12', '2017-12-12 09:46:12');
2424

2525

26-
# -------------------------------------以下biz业务库开始-------------------------------------------
27-
CREATE DATABASE IF NOT EXISTS pos default charset utf8 COLLATE utf8_general_ci;
26+
-- -------------------------------------以下biz业务库开始-------------------------------------------
27+
CREATE DATABASE IF NOT EXISTS biz default charset utf8 COLLATE utf8_general_ci;
2828
SET FOREIGN_KEY_CHECKS=0;
2929
USE biz;
3030

@@ -44,6 +44,6 @@ CREATE TABLE `t_user` (
4444
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='后台管理用户表';
4545

4646

47-
# 下面是biz数据库中的插入数据
47+
-- 下面是biz数据库中的插入数据
4848
INSERT INTO `t_user` VALUES (1,'admin1','系统管理员','123456','www', '17890908889', '系统管理员', 1, '2017-12-12 09:46:12', '2017-12-12 09:46:12');
4949
INSERT INTO `t_user` VALUES (2,'aix1','张三','123456','eee', '17859569358', '', 1, '2017-12-12 09:46:12', '2017-12-12 09:46:12');

springboot-multisource/src/test/java/com/xncoding/pos/ApplicationTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.slf4j.LoggerFactory;
99
import org.springframework.boot.test.context.SpringBootTest;
1010
import org.springframework.test.context.junit4.SpringRunner;
11+
import org.springframework.transaction.annotation.Transactional;
1112

1213
import javax.annotation.Resource;
1314

0 commit comments

Comments
 (0)