Files
SPC/ym-common/src/main/java/com/cnbm/common/aspect/RedisAspect.java
weihongyang 7aaa6700b3 commit init
2022-06-20 16:26:51 +08:00

42 lines
1.2 KiB
Java

package com.cnbm.common.aspect;
import com.cnbm.common.exception.ErrorCode;
import com.cnbm.common.exception.RenException;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
/**
* @Author weihongyang
* @Date 2022/6/7 2:58 PM
* @Version 1.0
*/
@Aspect
@Component
public class RedisAspect {
private Logger logger = LoggerFactory.getLogger(getClass());
/**
* 是否开启redis缓存 true开启 false关闭
*/
@Value("${renren.redis.open: false}")
private boolean open;
@Around("execution(* com.cnbm.common.redis.RedisUtils.*(..))")
public Object around(ProceedingJoinPoint point) throws Throwable {
Object result = null;
if(open){
try{
result = point.proceed();
}catch (Exception e){
logger.error("redis error", e);
throw new RenException(ErrorCode.REDIS_ERROR);
}
}
return result;
}
}