1.spring-context文件需要打开切面注解
<aop:aspectj-autoproxy proxy-target-class="true"/>
<context:annotation-config />
2.编写切面,如下,
package com.yeepay.g3.core.payplus.test.aspect;
import java.lang.reflect.Method;
import javax.annotation.Resource;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.StandardEvaluationContext;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;
import com.yeepay.g3.core.payplus.test.utils.MultiCache;
import com.yeepay.g3.core.payplus.test.utils.MultiCacheEvict;
import com.yeepay.g3.core.payplus.test.utils.RedisCacheBean;
@Component
@Aspect
public class CacheAspect {
@Resource
public RedisCacheBean redis;
/**
* 定义缓存逻辑
*/
@Around("@annotation(com.yeepay.g3.core.payplus.test.utils.MultiCache)")
public Object cache(ProceedingJoinPoint pjp ) {
Object result=null;
Boolean cacheEnable=true;
//判断是否开启缓存
if(!cacheEnable){
try {
result= pjp.proceed();
} catch (Throwable e) {