我想在我的 Spring 应用程序中使用 Spring AOP。在创建 AOP 代理时net.sf.ehcache.CacheManager
,spring 上下文初始化失败,出现以下异常:
nested exception is org.springframework.aop.framework.AopConfigException: Could not
generate CGLIB subclass of class [class net.sf.ehcache.CacheManager]: Common causes of
this problem include using a final class or a non-visible class; nested exception is
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.
The source of the existing CacheManager is: InputStreamConfigurationSource
[stream=java.io.ByteArrayInputStream@955b34]
这是我对这个问题的理解 - Spring 正在尝试为net.sf.ehcache.CacheManager
.__DEFAULT__
应用)。现在,如果我有多个缓存管理器,例如 'abcCacheManager' 和 'xyzCacheManager' (类型为 EhCacheManagerFactoryBean),Spring 会遇到多个net.sf.ehcache.CacheManager
s 并尝试为所有这些管理器创建代理对象(类似于net.sf.ehcache.CacheManager$$EnhancerByCGLIB$$b18c5958
),但是使用 EhCache >=2.5 版本,我们同一虚拟机下不能有多个同名缓存。
我正在使用 EhCache 2.5.1,并希望避免仅出于此目的回到 2.4。我不确定这是否真的是我如何克服这个问题的问题。
注意:请注意这是否会有所帮助,但我也从调试语句中注意到CacheManager
无参数构造函数仅由 spring/CGLIB 代理生成器xyzCacheManager
调用,并通过将配置作为参数传递来调用它。