Skip to content
This repository has been archived by the owner on Dec 25, 2019. It is now read-only.

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
crossoverJie committed Jan 4, 2017
1 parent 988c659 commit 82da979
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
12 changes: 10 additions & 2 deletions src/main/java/com/crossoverJie/util/DataSourceExchange.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,23 @@
import org.aspectj.lang.JoinPoint;

/**
* Function:
* Function:拦截器方法
*
* @author chenjiec
* Date: 2017/1/3 上午12:34
* @since JDK 1.7
*/
public class DataSourceExchange {


/**
* @param point
*/
public void before(JoinPoint point) {

//获取目标对象的类类型
Class<?> aClass = point.getTarget().getClass();

//获取包名用于区分不同数据源
String whichDataSource = aClass.getName().substring(25, aClass.getName().lastIndexOf("."));
if ("ssmone".equals(whichDataSource)) {
DataSourceHolder.setDataSources(Constants.DATASOURCE_ONE);
Expand All @@ -25,6 +30,9 @@ public void before(JoinPoint point) {
}


/**
* 执行后将数据源置为空
*/
public void after() {
DataSourceHolder.setDataSources(null);
}
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/com/crossoverJie/util/DynamicDataSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
* @since JDK 1.7
*/
public class DynamicDataSource extends AbstractRoutingDataSource {


@Override
protected Object determineCurrentLookupKey() {
return DataSourceHolder.getDataSources();
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/redis.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#redis中心
redis.host=27.126.180.210
redis.host=127.0.0.1
redis.port=6379
redis.password=tiger
redis.password=xxx
redis.maxIdle=100
redis.maxActive=300
redis.maxWait=1000
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/spring-mybatis.xml
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@

<aop:advisor advice-ref="methodCacheInterceptor" pointcut-ref="controllerMethodPointcut"/>

<!--所有数据库操作的方法加入切面-->
<aop:aspect ref="dataSourceExchange">
<aop:pointcut id="dataSourcePointcut" expression="execution(* com.crossoverJie.service.*.*(..))"/>
<aop:before pointcut-ref="dataSourcePointcut" method="before"/>
Expand Down

0 comments on commit 82da979

Please sign in to comment.