1 2 Previous Next 15 Replies Latest reply: Feb 21, 2013 6:42 AM by Stylianos Koussouris RSS

Using Infinispan cache in JBoss7

Mariusz Smykula Newbie

I need cache in my application (EAR) deployed on JBoss7. My cache look like this (in JBoss standalone.xml):

 

 

 

 

...
<subsystem xmlns="urn:jboss:domain:infinispan:1.0">
...
<cache-container name="myCache" default-cache="cachedb">
   <local-cache name="cachedb">
   </local-cache>
</cache-container>

 

 

 

I have configured Dependecy in EAR MANIFEST (maven)

 

<manifestEntries>
   <Dependencies>org.slf4j, org.apache.log4j, org.infinispan</Dependencies>
</manifestEntries>

 

 

 

I wanna access cache from EJB3 or from Spring Beans. What can I do?

 

@Resource(lookup="java:jboss/infinispan/myCache")  
private org.infinispan.manager.CacheContainer container;  
private org.infinispan.Cache<K, V> cache;

 

dosent work for me, is other way to do this?

  • 1. Re: Using Infinispan cache in JBoss7
    Kevin Pollet Newbie

    Hi,

     

    I think it should work.

     

    What's your version of JBoss AS 7?

    Where the injection is performed?

    Have you an exception when accessing the container instance or do you see something wrong in server log?

     

    --Kevin

  • 2. Re: Using Infinispan cache in JBoss7
    Mariusz Smykula Newbie

    Yes, it is working. I was thinking about other way to access cache.

     

    Is possible to configure TreeCache in JBoss7 Infinispan configuration file?

  • 3. Re: Using Infinispan cache in JBoss7
    Kevin Pollet Newbie

    Yes, it is working. I was thinking about other way to access cache.

     

    Cool :-)

     

    I'm not sure to understand what you mean by "other way to access cache"? (if you thought about accessing the cache container the only other way I see is to do a programmatic lookup)

     

    If you thought about accessing a cache you might be interested by the CDI support which provides a simple way to inject caches in EJB or CDI beans. Futhermore the CDI support can be used with cache defined in AS 7.

     

    Is possible to configure TreeCache in JBoss7 Infinispan configuration file?

     

    I'm not sure but I think it's not possible to configure a TreeCache in JBoss AS 7.

  • 4. Re: Using Infinispan cache in JBoss7
    Vitaliy Gonchar Newbie

    TreeCache works in jBoss AS 7.

    Did you manage how to lookup programmatic cache? I have problem with that.

    Thanks!

  • 5. Re: Using Infinispan cache in JBoss7
    Arun Ramachandran Newbie

    I m trying to implement the cache posted in this thread but while compling the code it fails with this error

     

    *.java:[25,11] cannot find symbol

    symbol  : method lookup()

    location: @interface javax.annotation.Resource

     

    i have used

     

    import javax.annotation.Resource;

     

    I dont think its the correct import?

    Can anyone help me on this?

     

    Thanks

     

     

  • 6. Re: Using Infinispan cache in JBoss7
    Kevin Pollet Newbie

    Hi,

     

    That's because you're using the version of common annotations bundled with the JDK.

    To use the new version with the lookup attribute you have to use the version 1.1 of common annotations (see http://docs.oracle.com/javaee/6/api/javax/annotation/Resource.html#lookup())

     

    If you're using Maven for the build look at the following post.

    If you're building without Maven just add the common annotations jar to the endorsed dir, look here.

     

    Hopes this help!

  • 7. Re: Using Infinispan cache in JBoss7
    Arun Ramachandran Newbie

    Hi,

     

    Thanks for the links it solved the issue. After deploying the application i see that the cache container is not getting initialized. It is always null. I have checked the server.log it does not have any errors but there is not logs relating to the cache also.

     

    Is there any other configurations to be done on top of this?

     

    Thanks

  • 8. Re: Using Infinispan cache in JBoss7
    Galder Zamarreño Master

    @Arun, what AS version is this? Did you try with our AS7 quickstart? https://github.com/infinispan/infinispan-quickstart/tree/master/jboss-as7

  • 9. Re: Using Infinispan cache in JBoss7
    Arun Ramachandran Newbie

    Hi,

     

     

    My JBoss v is 7.0.2 which uses uses infinispan-core-5.0.1.FINAL.jar

     

    I tried to deploy the quick starts but as the jar versions do not match and it does not deploy (due to class not found exceptions).

     

    Is there any guides available specific to Infinispan v5.0 ?

  • 10. Re: Using Infinispan cache in JBoss7
    Galder Zamarreño Master

    I'd suggest you try with Infinispan 5.1 and AS 7.1 since they both contains important fixes and improvements. Btw, I have a branch a branch for AS 7.1 but there's an issue with AS7 quickstart and domain mode which is being looked into. In case you wanna check: https://github.com/galderz/infinispan-quickstart/tree/t_710final/jboss-as7

     

    Anyway, if you're stuck in 7.0 and 5.0, the latest version that used that was https://github.com/infinispan/infinispan-quickstart/commit/e6369e4a705e7fe0ec3d8eef361c65822a724823, so you can simply clone the repository and checkout that commit and you should have the quickstarts ready for those versions.

  • 11. Re: Using Infinispan cache in JBoss7
    William O'Sullivan Newbie

    For JBoss 6 EAP (7.1.2 GA), I couldn't get the quickstart to work. Class not found error.

    Due to the new module structure in JBoss 7, I had to add the jboss-deployment-structure.xml to META-INF (at highest level in webapp)

     

    <?xml version="1.0" encoding="UTF-8"?>

    <jboss-deployment-structure>

              <deployment>

            <dependencies>

                <module name="org.infinispan" />

            </dependencies>

              </deployment>

    </jboss-deployment-structure>

     

    Attached is the server.log for your reference.

     

    WP

  • 12. Re: Using Infinispan cache in JBoss7
    Galder Zamarreño Master

    If you're using EAP 6, I assume you have a professional support contract. Such question should be directed to our professional support team.

  • 13. Re: Using Infinispan cache in JBoss7
    William O'Sullivan Newbie

    Hello Galder,

     

    Yes we do have a support agreement for JBoss. Currently almost all our production applications are on 4.2.3 EAP.

    My project is to propose a global SSO solution using CAS, and either JPA or Inifinispan. We cannot afford downtime.

     

    Since I was tasked with looking into in, I simply got my prototype to work using my talents and skills

     

    There was no real need to start a ticket, I am just helping out the community.

     

    If and when we go live, I am sure that there will be many opportunities to avail of our support agreements.

     

    WP

  • 14. Re: Using Infinispan cache in JBoss7
    Stylianos Koussouris Newbie

    A bit late in the day but does the following work for you inside a Spring bean?

    My intention is to access the distributed cache named "shortCache" which is configured within my JBoss 7 configuration.

     

    @Resource(lookup="java:jboss/infinispan/myCache")  
    private org.infinispan.manager.CacheContainer container;  
    private org.infinispan.Cache<K, V> cache;
    

    I get the following error which in my view it is kind of expected but I thought I'd try it reading this post.

     

    19:01:30,972 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/cache-service]] (MSC service thread 1-4) Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'shortCache': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [org.infinispan.manager.CacheContainer] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.annotation.Resource(shareable=true, mappedName=, description=, name=, type=class java.lang.Object, authenticationType=CONTAINER, lookup=java:jboss/infinispan/shortCache)}
         at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:307) [spring-context-3.1.2.RELEASE.jar:3.1.2.RELEASE]
         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1106) [spring-beans-3.1.2.RELEASE.jar:3.1.2.RELEASE]
         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517) [spring-beans-3.1.2.RELEASE.jar:3.1.2.RELEASE]
         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) [spring-beans-3.1.2.RELEASE.jar:3.1.2.RELEASE]
         at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294) [spring-beans-3.1.2.RELEASE.jar:3.1.2.RELEASE]
         at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225) [spring-beans-3.1.2.RELEASE.jar:3.1.2.RELEASE]
         at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291) [spring-beans-3.1.2.RELEASE.jar:3.1.2.RELEASE]
         at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) [spring-beans-3.1.2.RELEASE.jar:3.1.2.RELEASE]
         at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:609) [spring-beans-3.1.2.RELEASE.jar:3.1.2.RELEASE]
         at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) [spring-context-3.1.2.RELEASE.jar:3.1.2.RELEASE]
         at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:469) [spring-context-3.1.2.RELEASE.jar:3.1.2.RELEASE]
         at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:383) [spring-web-3.1.2.RELEASE.jar:3.1.2.RELEASE]
         at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283) [spring-web-3.1.2.RELEASE.jar:3.1.2.RELEASE]
         at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111) [spring-web-3.1.2.RELEASE.jar:3.1.2.RELEASE]
         at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:3392) [jbossweb-7.0.16.Final.jar:]
         at org.apache.catalina.core.StandardContext.start(StandardContext.java:3850) [jbossweb-7.0.16.Final.jar:]
         at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:90) [jboss-as-web-7.1.2.Final.jar:7.1.2.Final]
         at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
         at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
         at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [rt.jar:1.6.0_31]
         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [rt.jar:1.6.0_31]
         at java.lang.Thread.run(Thread.java:662) [rt.jar:1.6.0_31]
     Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [org.infinispan.manager.CacheContainer] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.annotation.Resource(shareable=true, mappedName=, description=, name=, type=class java.lang.Object, authenticationType=CONTAINER, lookup=java:jboss/infinispan/shortCache)}
         at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:952) [spring-beans-3.1.2.RELEASE.jar:3.1.2.RELEASE]
         at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:821) [spring-beans-3.1.2.RELEASE.jar:3.1.2.RELEASE]
         at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:735) [spring-beans-3.1.2.RELEASE.jar:3.1.2.RELEASE]
         at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:439) [spring-context-3.1.2.RELEASE.jar:3.1.2.RELEASE]
         at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:417) [spring-context-3.1.2.RELEASE.jar:3.1.2.RELEASE]
         at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:559) [spring-context-3.1.2.RELEASE.jar:3.1.2.RELEASE]
         at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:150) [spring-beans-3.1.2.RELEASE.jar:3.1.2.RELEASE]
         at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87) [spring-beans-3.1.2.RELEASE.jar:3.1.2.RELEASE]
         at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:304) [spring-context-3.1.2.RELEASE.jar:3.1.2.RELEASE]
    
        ... 21 more
    
1 2 Previous Next