数据库主从架构过程,参考https://www.cnblogs.com/cloudhere/p/10991520.html。
java关于主从的应用在这里写一下:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
<version>2.2.2.RELEASE</version>
</dependency>
@Aspect
@Component
@Order(1)
public class DataSourceAop {
//公共参数,创建时间
private static final String CREATE_DATE = "createDate";
//修改时间
private static final String UPDATE_DATE = "updateDate";
/**
* 只读方法的设置
*/
@Pointcut("execution(* com.haozi.miaoshaproject.service.impl..*.select*(..))"
+ "|| execution(* com.haozi.miaoshaproject.service.impl..*.find*(..))"
+ "|| execution(* com.haozi.miaoshaproject.service.impl..*.get*(..))")
public void readonlyPointcut(){
}
/**
* 读写方法的设置
*/
@Pointcut("execution(* com.haozi.miaoshaproject.service.impl..*.save*(..))"
+ "|| execution(* com.haozi.miaoshaproject.service.impl..*.update*(..))"
+ "|| execution(* com.haozi.miaoshaproject.service.impl..*.insert*(..))"
+ "|| execution(* com.haozi.miaoshaproject.service.impl..*.add*(..))")
public void writePointcut(){
}
/**
* 具体切入
* @param joinPoint
*/
@Before("writePointcut()