开发者

unable to inject seam cache provider

开发者 https://www.devze.com 2023-01-03 10:47 出处:网络
Env: Seam 2.2, ehcache-core 2.1.0 I tried injecting the CacheProvider using the following call in my bean scoped for session

Env: Seam 2.2, ehcache-core 2.1.0

I tried injecting the CacheProvider using the following call in my bean scoped for session

    @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         
C开发者_开发知识库acheProvider 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.

What am I missing here?


Keep in mind net.sf.ehcache.Cache needs to be on the classpath (I am not sure but I Think ehcache-core.jar contains this class) if you want to use EhCahceProvider. Here goes its signature

@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> {

Notice classDependencies attribute. Its documentation is clear

Indicates that the component should not be installed unless the the given class definitions are available on the classpath

So if your classpath contains net.sf.ehcache.Cache you do not need to declare

<cache:eh-cache-provider/>

And as it is Application scoped, you can retrieve, besides @In-jection, by using

ApplicationContext.getContext().get("cacheProvider");

UPDATE

First of all

  • remove <cache:eh-cache-provider/> declaration. I said you why (see above)

Second of all

  • Although i am pretty sure CacheProvider can not be null because @In required attribute is, by default, true, which cannot be null. Inside your business method, Make sure your CacheProvider is not null

    assert cacheProvider != null

Third of all

  • I Think you do not need to call cacheProvider.instance() method. If its default scope is Application. Why do you want to retrieve another CacheProvider ??? It does not make sense.

Fourth of all

  • It is not an exception. Its is just a warning message because you is trying to use more than one cache provider where both use the same space in memory
0

精彩评论

暂无评论...
验证码 换一张
取 消