From c84c9150bd54583c11ca9000948a697fe366bf82 Mon Sep 17 00:00:00 2001 From: Xiong Neng Date: Sat, 15 Sep 2018 14:31:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90springboot-multisource?= =?UTF-8?q?=E5=8D=87=E7=BA=A7=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/xncoding/pos/service/UserService.java | 2 ++ .../src/main/resources/application.yml | 32 ++----------------- .../src/main/resources/sql/schema.sql | 10 +++--- .../com/xncoding/pos/ApplicationTests.java | 1 + 4 files changed, 11 insertions(+), 34 deletions(-) diff --git a/springboot-multisource/src/main/java/com/xncoding/pos/service/UserService.java b/springboot-multisource/src/main/java/com/xncoding/pos/service/UserService.java index f4e6a19..26cdf56 100644 --- a/springboot-multisource/src/main/java/com/xncoding/pos/service/UserService.java +++ b/springboot-multisource/src/main/java/com/xncoding/pos/service/UserService.java @@ -5,6 +5,7 @@ import com.xncoding.pos.common.dao.entity.User; import com.xncoding.pos.common.dao.repository.UserMapper; import com.xncoding.pos.common.mutidatesource.DSEnum; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; @@ -13,6 +14,7 @@ import javax.annotation.Resource; */ @Service +@Transactional public class UserService { @Resource diff --git a/springboot-multisource/src/main/resources/application.yml b/springboot-multisource/src/main/resources/application.yml index f771764..2a66523 100644 --- a/springboot-multisource/src/main/resources/application.yml +++ b/springboot-multisource/src/main/resources/application.yml @@ -38,14 +38,14 @@ logging: spring: profiles: dev datasource: - url: jdbc:mysql://127.0.0.1:3306/pos?useSSL=false&autoReconnect=true&tinyInt1isBit=false&useUnicode=true&characterEncoding=utf8 + url: jdbc:mysql://127.0.0.1:3306/pos?serverTimezone=UTC&useSSL=false&autoReconnect=true&tinyInt1isBit=false&useUnicode=true&characterEncoding=utf8 username: root password: 123456 #多数据源 biz: datasource: - url: jdbc:mysql://127.0.0.1:3306/biz?useSSL=false&autoReconnect=true&tinyInt1isBit=false&useUnicode=true&characterEncoding=utf8 + url: jdbc:mysql://127.0.0.1:3306/biz?serverTimezone=UTC&useSSL=false&autoReconnect=true&tinyInt1isBit=false&useUnicode=true&characterEncoding=utf8 username: root password: 123456 @@ -54,31 +54,5 @@ logging: ROOT: INFO com: xncoding: DEBUG - file: E:/logs/app.log + file: D:/logs/app.log ---- - -##################################################################### -######################## 测试环境profile ########################## -##################################################################### - -spring: - profiles: test - datasource: - url: jdbc:mysql://127.0.0.1:3306/pos?useSSL=false&autoReconnect=true&tinyInt1isBit=false&useUnicode=true&characterEncoding=utf8 - username: root - password: 123456 - -#多数据源 -biz: - datasource: - url: jdbc:mysql://127.0.0.1:3306/biz?useSSL=false&autoReconnect=true&tinyInt1isBit=false&useUnicode=true&characterEncoding=utf8 - username: root - password: 123456 - -logging: - level: - ROOT: INFO - com: - xncoding: DEBUG - file: /var/logs/app.log diff --git a/springboot-multisource/src/main/resources/sql/schema.sql b/springboot-multisource/src/main/resources/sql/schema.sql index 2b3b17b..e334514 100644 --- a/springboot-multisource/src/main/resources/sql/schema.sql +++ b/springboot-multisource/src/main/resources/sql/schema.sql @@ -1,4 +1,4 @@ -# -------------------------------------以下是pos业务库开始------------------------------------------- +-- -------------------------------------以下是pos业务库开始------------------------------------------- CREATE DATABASE IF NOT EXISTS pos default charset utf8 COLLATE utf8_general_ci; SET FOREIGN_KEY_CHECKS=0; USE pos; @@ -18,13 +18,13 @@ CREATE TABLE `t_user` ( `updated_time` DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间' ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='后台管理用户表'; -# 下面是pos数据库中的插入数据 +-- 下面是pos数据库中的插入数据 INSERT INTO `t_user` VALUES (1,'admin','系统管理员','123456','www', '17890908889', '系统管理员', 1, '2017-12-12 09:46:12', '2017-12-12 09:46:12'); INSERT INTO `t_user` VALUES (2,'aix','张三','123456','eee', '17859569358', '', 1, '2017-12-12 09:46:12', '2017-12-12 09:46:12'); -# -------------------------------------以下biz业务库开始------------------------------------------- -CREATE DATABASE IF NOT EXISTS pos default charset utf8 COLLATE utf8_general_ci; +-- -------------------------------------以下biz业务库开始------------------------------------------- +CREATE DATABASE IF NOT EXISTS biz default charset utf8 COLLATE utf8_general_ci; SET FOREIGN_KEY_CHECKS=0; USE biz; @@ -44,6 +44,6 @@ CREATE TABLE `t_user` ( ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='后台管理用户表'; -# 下面是biz数据库中的插入数据 +-- 下面是biz数据库中的插入数据 INSERT INTO `t_user` VALUES (1,'admin1','系统管理员','123456','www', '17890908889', '系统管理员', 1, '2017-12-12 09:46:12', '2017-12-12 09:46:12'); INSERT INTO `t_user` VALUES (2,'aix1','张三','123456','eee', '17859569358', '', 1, '2017-12-12 09:46:12', '2017-12-12 09:46:12'); diff --git a/springboot-multisource/src/test/java/com/xncoding/pos/ApplicationTests.java b/springboot-multisource/src/test/java/com/xncoding/pos/ApplicationTests.java index 1c5cd84..a7b159a 100644 --- a/springboot-multisource/src/test/java/com/xncoding/pos/ApplicationTests.java +++ b/springboot-multisource/src/test/java/com/xncoding/pos/ApplicationTests.java @@ -8,6 +8,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource;