今天搭框架想用基于注解实现切面的功能,结果报错error Type referred to is not an annotation type:RedisCache
代码如下:
注解:
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Documented
public @interface RedisCache {
public String key() default "";
public long TTL() default 0L;
}
切面:
@Around("@annotation(redisCache)")
public void redisCache(ProceedingJoinPoint joinPoint,RedisCache redisCache){
String targetName = joinPoint.getTarget().getClass().getName();
String methodName = joinPoint.getSignature().getName();
Object[] arguments = joinPoint.getArgs();
Object result = null;
String cacheKey = getCacheKey(targetName, methodName, arguments);
System.out.println("哈哈哈"+cacheKey);
}
原来注解必须作为参数传进来,而且红色的地方必须一样。