1 Reply Latest reply on Feb 12, 2013 9:44 AM by amanukyan

    Unable to lookup Infinispan cache in EJB

    mylos78

      Hi all,

      I'm trying to store some values in Infinispan cache from within an EJB 3.1 Singleton that is running on a clustered JBoss AS 7.1.1.

      In the PostConstruct of my EJB Singleton I have:

       

      @PostConstruct  public void start() {

        InitialContext ic = new InitialContext();

        CacheContainer cc = (CacheContainer) ic.lookup("java:jboss/infinispan/cluster");

        . . .

      }

      However the following error is raised:

      16:52:30,678 ERROR [stderr] (MSC service thread 1-4) javax.naming.NameNotFoundException: infinispan/cluster -- service jboss.naming.context.java.jboss.infinispan.cluster

       

      I have correctly exported Infinispan dependencies in the JAR file

      Dependencies: org.infinispan export

       

      I have tried also with dependency injection:

        @Resource(lookup="java:jboss/infinispan/cluster")

        private org.infinispan.manager.CacheContainer container;

       

      But I still get the same error :-(

      I have tried it both on JBoss AS 7.1.1 and on EAP (trial) 6.0.1.

      Any help ???

      Mylos

        • 1. Re: Unable to lookup Infinispan cache in EJB
          amanukyan

          Hi Mylos,

           

          for getting Infinispan cache manager being injected you need to do the following:

           

          e.g. assume you have some container defined in your EAP or JBoss AS standalone-*.xml defined and you want to inject it. The important thing that should be done is - you need to define jndi-name attribute for that container so that you can get it later via injection.

           

          <subsystem xmlns="urn:jboss:domain:infinispan:1.2" default-cache-container="cluster">

          ....

          <cache-container name="cluster" aliases="ha-partition" default-cache="default" jndi-name="java:jboss/infinispan/cluster">

                          <transport lock-timeout="60000"/>

                          <replicated-cache name="default" mode="SYNC" batching="true">

                              <locking isolation="REPEATABLE_READ"/>

                          </replicated-cache>

                      </cache-container>

          </synsystem>

           

          Then in your code, the following line will inject the cache manager properly.

            @Resource(lookup="java:jboss/infinispan/cluster")

            private org.infinispan.manager.CacheContainer container;

           

          Hope this will help.

           

          Regards,

          Anna.