1 Reply Latest reply on Mar 13, 2014 5:39 PM by Claus Elsborg

    Infinispan 6.0.1.Final, WildFly 8.0.0.Final and CDI throws an exception when injecting Cache

    Claus Elsborg Newbie

      The following code worked perfectly in JBoss EAP 6.2 with the bundled Infinipan 5.2.7

       

      public class CacheManager {
      
      
          @Resource(lookup="java:jboss/infinispan/container/my-cache")
          private EmbeddedCacheManager myCacheManager;
      
      
          @Produces
          @StageCache
          @ApplicationScoped
          public Cache<StageKey, Stage> stageCache() {
              return myCacheManager.getCache("stage-cache");
          }
      }
      
      

       

      my-cache is defined in standalone.xml:

       

      <cache-container name="my-cache" default-cache="my-cache-default">

                      <local-cache name="my-cache-default"/>

                      <local-cache name="stage-cache">

                          <file-store preload="true" passivation="false" purge="false"/>

                      </local-cache>

                      ....

       

      The Cache is then Injected in another class using:

       

      @Inject
      @StageCache
      Cache<StageKey, Stage> stageCache;
      

       

      But, when using the injected cache, an exception is thrown:

       

      ...

      Caused by: java.lang.IllegalArgumentException: object is not an instance of declaring class

        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_40]

        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_40]

        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_40]

        at java.lang.reflect.Method.invoke(Method.java:606) [rt.jar:1.7.0_40]

        at org.jboss.weld.bean.proxy.AbstractBeanInstance.invoke(AbstractBeanInstance.java:40) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23]

        at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:100) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23]

        at org.jboss.weld.proxies.AsyncCache$BasicCache$BasicCache$BatchingCache$Cache$ConcurrentMap$FilteringListenable$Lifecycle$Listenable$Map$257467401$Proxy$_$$_WeldClientProxy.put(Unknown Source) [weld-core-impl-2.1.2.Final.jar:]

      ...

       

      Any ideas why this happens? Using the cache without Cache injection by doing myCacheManager.getCache("stage-cache").put(...) works fine.

        • 1. Re: Infinispan 6.0.1.Final, WildFly 8.0.0.Final and CDI throws an exception when injecting Cache
          Claus Elsborg Newbie

          OK, figured it out.

           

          I needed to export org.infinispan.commons. For Infinispan 5.x only org.infinispan was needed in MANIFEST.MF or jboss-deployment-structure.xml

          The following works for me:

           

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

          <jboss-deployment-structure>

              <deployment>

                  <dependencies>

                      <module name="org.infinispan"/>

                      <module name="org.infinispan.commons"/>

                  </dependencies>

              </deployment>

          </jboss-deployment-structure>

           

          I believe this is not documented. At least I can't find it mentioned anywhere.