Caching 无法注入seam缓存提供程序

Caching 无法注入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

环境: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 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???这没有意义
第四

  • 这也不例外。这只是一条警告消息,因为您试图使用多个缓存提供程序,其中两个都使用相同的内存空间

我正在使用ehcache-core.jar。我还需要lib文件夹中的ehcache.jar吗?只是出于好奇:你以前使用过缓存提供程序吗???您说过您的@In-jected组件似乎返回null,但它不能返回null,因为@In注释中的必需属性默认为true,这意味着它不能为null。否则,您将得到Seam抛出的异常。您遵循哪个教程???它似乎不会引发异常,缓存提供程序只是空的。查询缓存和第二级缓存似乎工作正常,尽管我在这里没有选项,但仍然无法找出此问题的原因:(net.sf.ehcache.Cache是ehcache-core.jar的一部分,存在于ear\lib文件夹中。我尝试了以下方法,但似乎都无效//CacheProvider CacheProvider=CacheProvider.instance();或CacheProvider CacheProvider=(CacheProvider)context.getApplicationContext().get(“CacheProvider”);或@In CacheProvider CacheProvider;@Joshua确保war lib文件夹不包含ehcache-core.jar一旦存储在ear lib folder中jar只存在于ear\lib folderI删除了声明,但仍然出现空指针异常。@Joshua.我相信你。周末,我会亲自尝试你想做的事。B让我知道:你使用哪个应用服务器???EAR还是WAR???
<cache:eh-cache-provider/>
ApplicationContext.getContext().get("cacheProvider");