From e94cb3e1b4d6010fa9ee8f12230094b1ea0e5582 Mon Sep 17 00:00:00 2001 From: sun5769675 Date: Tue, 28 May 2019 21:27:47 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20README.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 57c9f96..9b0e10f 100644 --- a/README.md +++ b/README.md @@ -14,12 +14,12 @@ springboot-mybatis-wr-separation is a Maven project based on SpringBoot and Myba com.gitee.sunchenbin springboot-mybatis-wr-separation - 0.0.1.RELEASE + 0.0.2.RELEASE 2. application.properties中需要做如下配置 - (1) mybatis的配置 + (1) mybatis的配置(根据自己的配置来) mybatis.mapperLocations=classpath:sql-mapper/**/*.xml mybatis.typeAliasesPackage=com.xxx.api.xxx.model,com.xxx.api.xxx.command @@ -33,16 +33,17 @@ springboot-mybatis-wr-separation is a Maven project based on SpringBoot and Myba spring.datasource.read.username=root spring.datasource.read.password=123456 spring.datasource.read.driver-class-name=org.postgresql.Driver + + (3) 读写分离切点的expression表达式(建议切manager或者service) + wr.separation.pointcut.expression=execution(public * com.xxx..*.*(..)) 3. 应用插件的springboot项目需要配置扫码插件的包,即@ComponentScan需要配置对"com.gitee.sunshine.*"包路径的扫描 #### 使用说明 -1. 本插件提供两个注解,@WriteDB(走写库)、@ReadDB(走读库) +1. 本插件提供一个注解,@ReadDB(走读库),如果不打注解默认走写库 2. 注解适用范围,必须是spring管理的bean的方法,注解不支持打在接口方法上,通常来说建议在manager层service层的方法上使用 -3. 注解生命周期,作用于当前线程,如果当前线程的,有任意一个地方设置了@WriteDB或者@ReadDB,那么本线程之后都以此设置作为数据源,这是为了避免来回切换导致的事务问题,如果整个线程没有设置这个注解,那么默认使用写库。 - -4. 如果整个线程里执行的方法都没有打这两个注解中的任意一个,那么默认走写库。 +3. 注解生命周期,为了避免读库写库来回切换,产生的事务问题,这里规定,当前线程只会使用一个库去执行操作,比如a.test1()被调用时,首先a是被spring管理的类,并且他在我们配置文件“读写分离切点表达式”的范围内,那么此时,如果test1()打了注解@ReadDB,那么从此开始直到这个线程结束了,都使用读库,如果没有打注解,那么从此开始知道整个线程结束了都使用写库。 -- Gitee From 34bf72a19764b7d6f27ba491c672c022b12b5323 Mon Sep 17 00:00:00 2001 From: "chenbin.sun" Date: Wed, 29 May 2019 10:06:27 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E5=8D=87=E7=BA=A7=E7=89=88=E6=9C=AC0.0.3.R?= =?UTF-8?q?ELEASE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- src/main/java/com/gitee/sunshine/factory/StackContext.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 9b2131c..6531d9f 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.gitee.sunchenbin springboot-mybatis-wr-separation - 0.0.2.RELEASE + 0.0.3.RELEASE jar diff --git a/src/main/java/com/gitee/sunshine/factory/StackContext.java b/src/main/java/com/gitee/sunshine/factory/StackContext.java index a303e42..154dd81 100644 --- a/src/main/java/com/gitee/sunshine/factory/StackContext.java +++ b/src/main/java/com/gitee/sunshine/factory/StackContext.java @@ -12,7 +12,7 @@ public class StackContext implements ServiceInvocationContext { public static final String TRANSACTIONID_FORMAT_STRING = "%s-%s-%s"; - private Stack invocationStatusStack = new Stack<>(); + private Stack invocationStatusStack = new Stack(); @Override public InvocationStatus createInvocation(MethodInvocation invocation) { @@ -44,7 +44,7 @@ public class StackContext implements ServiceInvocationContext { @Override public void clean() { - this.invocationStatusStack = new Stack<>(); + this.invocationStatusStack = new Stack(); } private String createTransactionId() { -- Gitee From 5f385a6bf6558c5ef9adb508127553e100ae1574 Mon Sep 17 00:00:00 2001 From: sun5769675 Date: Wed, 29 May 2019 10:08:27 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20README.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9b0e10f..10045ee 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ springboot-mybatis-wr-separation is a Maven project based on SpringBoot and Myba com.gitee.sunchenbin springboot-mybatis-wr-separation - 0.0.2.RELEASE + 0.0.3.RELEASE 2. application.properties中需要做如下配置 -- Gitee