Caching 无法注入seam缓存提供程序
环境:Seam 2.2,ehcache核心2.1.0 我尝试在会话的bean作用域中使用以下调用注入CacheProviderCaching 无法注入seam缓存提供程序,caching,seam,ehcache,Caching,Seam,Ehcache,环境:Seam 2.2,ehcache核心2.1.0 我尝试在会话的bean作用域中使用以下调用注入CacheProvider @In CacheProvider cacheProvider; WEB-INF\components.xml contains the following line to enable the cache provider <cache:eh-cache-provider/> The above configuration se
@In CacheProvider cacheProvider;
WEB-INF\components.xml contains the following line to enable the cache provider
<cache:eh-cache-provider/>
The above configuration seems to return a null value for the cache provider
Using the cache provider like this
CacheProvider cacheProvider = CacheProvider.instance();
throws the following warning
15:29:27,586 WARN [CacheManager] Creating a new instance of CacheManager using
the diskStorePath "C:\DOCUME~1\user5\LOCALS~1\Temp\" which is already used by an
existing CacheManager.
The source of the configuration was net.sf.ehcache.config.generator.Configuratio
nSource$DefaultConfigurationSource@15ed0f9.
The diskStore path for this CacheManager will be set to C:\DOCUME~1\user5\LOCALS
~1\Temp\\ehcache_auto_created_1276682367586.
To avoid this warning consider using the CacheManager factory methods to create
a singleton CacheManager or specifying a separate ehcache configuration (ehcache
.xml) for each CacheManager instance.
CacheProvider中的@;
WEB-INF\components.xml包含以下行以启用缓存提供程序
上述配置似乎为缓存提供程序返回空值
像这样使用缓存提供程序
CacheProvider CacheProvider=CacheProvider.instance();
抛出以下警告
15:29:27586警告[CacheManager]使用创建CacheManager的新实例
磁盘存储路径“C:\DOCUME~1\user5\LOCALS~1\Temp\”已由
现有缓存管理器。
配置的源是net.sf.ehcache.config.generator.Configuratio
来源$DefaultConfigurationSource@15ed0f9.
此CacheManager的diskStore路径将设置为C:\DOCUME~1\user5\LOCALS
~1\Temp\\ehcache\u auto\u created\u 1276682367586。
若要避免此警告,请考虑使用CaseMaMaGeFr工厂方法创建
单例缓存管理器或指定单独的ehcache配置(ehcache
.xml),用于每个CacheManager实例。
这里我遗漏了什么?请记住net.sf.ehcache.Cache需要位于类路径上(我不确定,但我认为ehcache-core.jar包含此类),如果您想使用EhCahceProvider。这是它的签名
@Name("org.jboss.seam.cache.cacheProvider")
@Scope(APPLICATION)
@BypassInterceptors
@Install(value = false, precedence=BUILT_IN, classDependencies="net.sf.ehcache.Cache")
@AutoCreate
public class EhCacheProvider extends CacheProvider<CacheManager> {
更新
首先
- 删除声明。我告诉你为什么(见上文)
- 尽管我非常确定CacheProvider不能为null,因为@In required属性默认为true,不能为null。在业务方法中,确保CacheProvider不为null 断言缓存提供程序!=空的
- 我认为您不需要调用cacheProvider.instance()方法。如果其默认范围是Application为什么要检索另一个CacheProvider???这没有意义
- 这也不例外。这只是一条警告消息,因为您试图使用多个缓存提供程序,其中两个都使用相同的内存空间
<cache:eh-cache-provider/>
ApplicationContext.getContext().get("cacheProvider");