即使类实现接口时也使用CGLIB代理的Spring接口、CGLIB、Spring

2023-09-03 14:36:13 作者:柠檬校草。

我正在尝试使用Spring AOP来拦截我的GWT-RPC应用程序的方法(使用GWT-Server库,这样RPC服务就不会扩展RemoteServiceServlet)。当我将WAR部署到Tomcat并启动应用程序时,CGLIB由于某种原因而失败。但我不明白为什么CGLIB一开始就被用来代理。既然我的RPC类实现了接口,它不应该使用JDK动态代理吗?

我需要执行什么操作才能调试此问题?敬请指教。

这份1658页的 Java岗面试核心MCA版 ,从GitHub火到了B站 拿走不谢

注意:仅供参考,Spring遇到此异常,但我认为这是另一个问题,我无法理解为什么CGLIB代理会出现在图片中。

Caused by: net.sf.cglib.core.CodeGenerationException: net.sf.ehcache.CacheException-->Another unnamed CacheManager already exists 
in the same VM. Please provide unique names for each CacheManager in the config 
or do one of following:
1. Use one of the CacheManager.create() static factory methods to reuse same    CacheManager with same name or create one if necessary
2. Shutdown the earlier cacheManager before creating new one with same name.

推荐答案

为其他(极少数)可能会犯同样错误的人回答。

Spring AOP的方面设置不正确,实际上试图以上下文中的几乎所有类为目标,这就是EhCache开始导致问题的原因,因为有多个CacheManager实例(由于CGLIB代理,因为CacheManager不实现接口)