环境:Seam 2.2,ehcache-core 2.1.0
我尝试在我的bean作为会话
的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.
我在这里缺少什么?
答案 0 :(得分:1)
请记住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> {
注意classDependencies属性。它的文件很清楚
表示不应安装组件 ,除非 类路径上可用的给定类定义
因此,如果您的类路径包含net.sf.ehcache.Cache ,则无需声明
<cache:eh-cache-provider/>
由于它是应用程序作用域,除了@In-jection之外,您还可以使用
检索ApplicationContext.getContext().get("cacheProvider");
<强>更新强>
首先
其次
虽然我非常确定CacheProvider 不能为空,因为@In required属性默认为true,不能为null。在您的业务方法中,确保您的CacheProvider不为空
断言cacheProvider!= null
第三个
总之