我尝试了以下代码,但它不起作用:
@Component
@Aspect
@Order(Integer.MAX_VALUE)
public class CacheAspect {
@Around("execution(public * org.springframework.cache.interceptor.CacheInterceptor.invoke(..))")
public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
//CLASS_CACHE.set(signature.getReturnType());
return joinPoint.proceed();
}
}
P.S。我确信CacheInterceptor
是一个弹簧托管bean。
答案 0 :(得分:2)
经过一些实验,我发现用CacheInterceptor
替换 @Configuration
@EnableCaching
@Profile("test")
public class CacheConfig {
@Bean
@Autowired
public CacheManager cacheManager(RedisClientTemplate redisClientTemplate) {
return new ConcurrentMapCacheManager(redisClientTemplate, "test");
}
@Bean
public CacheOperationSource cacheOperationSource() {
return new AnnotationCacheOperationSource();
}
@Bean
public CacheInterceptor cacheInterceptor() {
CacheInterceptor interceptor = new MyCacheInterceptor();
interceptor.setCacheOperationSources(cacheOperationSource());
return interceptor;
}
}
内置的弹簧可以解决我的问题。
这是代码,以防有人有类似的要求。
CacheAspect
MyCacheInterceptor.java,与 public class MyCacheInterceptor extends CacheInterceptor {
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
Method method = invocation.getMethod();
//CLASS_CACHE.set(signature.getReturnType());
return super.invoke(invocation);
}
}
:
CacheInterceptor
可以在ProxyCachingConfiguration
类中找到href="<%= asset_path('styles-bluegreen.css')%>"
bean中内置的spring。
希望它有所帮助。