views:

340

answers:

2

Hi every one,

I'm trying to configure seam/ehcache following the tutorial from jboss page:

http://docs.jboss.org/seam/2.1.2/reference/en-US/html/cache.html

I put the ehcache.1.2.3.jar in project.ear/lib and injected CacheProvider as especified, but the CacheProvider always return null. The documentation doesn't show any aditional configuration for ehcache, just for jboss cache.

I am probably doing something wrong, it's impossible be so easy :).

besides put the jar in /lib, i created the following seam component to test:

@Scope(ScopeType.SESSION)
@Name("cacheBean")
public class CacheSeamBean implements java.io.Serializable {

 @In(required=false, create=true) 
 private EntityManager em;

 @Logger 
 private Log log;

 @In
 private Events events;

 @In CacheProvider cacheProvider;

 Boolean blLoaded = Boolean.FALSE;

 @Create
 public void buscar() {

  if (!blLoaded){
   List<Parametro> lstParametro = em.createQuery("select p from Parametro p").getResultList();
   for (Parametro parametro : lstParametro){
    cacheProvider.put(parametro.getCodigo(), parametro.getValor());
   }
   blLoaded= Boolean.TRUE;
  }
 }
}

Thanks

A: 

CacheProvider always return null

What do you mean? CacheProvider reference (cacheProvider) is null, or cacheProvider.get(key) always returns null?

Vladimir Dyuzhev
cacheProvider variable is null ... but that's ok, i was looking for some tutorials about cache in hibernate and found out that ehcache can't be clustered, and this is not usefull for me. I'll try Jboss Treecache instead of ehcache. P.S in wiki example from jboss 2.1.2 package, there is a configuration for ehcache and it is totally different from jboss tutorial that i have read
Cateno Viglio
cache provider is null for me with seam 2.2
Joshua
+1  A: 

Add into your components.xml:

<components xmlns="http://jboss.com/products/seam/components"
...
            xmlns:cache="http://jboss.com/products/seam/cache"
            xsi:schemaLocation=
                    "http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.1.xsd
               http://jboss.com/products/seam/cache http://www.jboss.com/products/seam/cache-2.1.xsd"&gt;

...
   <cache:eh-cache-provider/>
...
</components>
Joff
I added the above snippet in the components.xml and it still didn't work for me.
Joshua
@Joshua do you have the ehcache jar in the classpath? (project.ear/lib) that's all you should need to get it working. If you have a non-default ehcache.xml, that needs to be in the root of your application classpath too, (eg WEB-INF/classes)
Joff