package com.ld.igds.aop;
|
|
import com.ld.igds.annotation.DataSource;
|
import com.ld.igds.conf.DataSourceContextHolder;
|
import lombok.extern.slf4j.Slf4j;
|
import org.aspectj.lang.annotation.After;
|
import org.aspectj.lang.annotation.Aspect;
|
import org.aspectj.lang.annotation.Before;
|
import org.aspectj.lang.annotation.Pointcut;
|
import org.springframework.core.annotation.Order;
|
import org.springframework.stereotype.Component;
|
|
/**
|
* 在使用不同数据源时候,使用@DatSource注解
|
* @author Andy
|
*
|
*/
|
@Slf4j
|
@Component
|
@Aspect
|
@Order(-100)
|
public class DataSourceAspect {
|
|
@Pointcut("@within(com.ld.igds.annotation.DataSource) || "
|
+ "@annotation(com.ld.igds.annotation.DataSource)")
|
public void pointCut() {
|
|
}
|
|
@Before("pointCut() && @annotation(dataSource)")
|
public void doBefore(DataSource dataSource) {
|
log.debug("当前选择的数据源为:{}",dataSource.value().getValue());
|
DataSourceContextHolder.setDataSource(dataSource.value().getValue());
|
}
|
|
@After("pointCut()")
|
public void doAfter() {
|
DataSourceContextHolder.clear();
|
}
|
}
|