java – spring aop截取org.springframework.cache.interceptor.CacheInterceptor #incoke
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了java – spring aop截取org.springframework.cache.interceptor.CacheInterceptor #incoke,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1493字,纯文字阅读大概需要3分钟。
内容图文
我尝试了以下代码,但它不起作用:
@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();
}
}
附:我确信CacheInterceptor是一个Spring托管bean.
解决方法:
经过一些实验,我发现用用户定义的CacheInterceptor替换内置的Spring可以解决我的问题.
这是代码,以防有人有类似的要求.
@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;
}
}
MyCacheInterceptor.java,与CacheAspect共享相同的逻辑:
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);
}
}
可以在ProxyCachingConfiguration类中找到CacheInterceptor bean中构建的spring.
希望能帮助到你.
内容总结
以上是互联网集市为您收集整理的java – spring aop截取org.springframework.cache.interceptor.CacheInterceptor #incoke全部内容,希望文章能够帮你解决java – spring aop截取org.springframework.cache.interceptor.CacheInterceptor #incoke所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。