12 Replies Latest reply on Feb 19, 2018 1:27 AM by siva.munnaluri

    Cache Injection in Spring

    siva.munnaluri

      I created a cache container and created cache under the cache container .

       

      if (outcome != success) of /subsystem=infinispan/cache-container=musi:read-resource

        /subsystem=infinispan/cache-container=musi:add(\

        default-cache=et-default-cache,\

        jndi-name=java:jboss/infinispan/container/musi\

        )

      end-if

       

      if (outcome != success) of /subsystem=infinispan/cache-container=musi/invalidation-cache=configuration:read-resource

        /subsystem=infinispan/cache-container=musi/invalidation-cache=configuration:add(\

        mode=ASYNC,\

        async-marshalling=true,\

        jndi-name=java:jboss/infinispan/container/musi/configuration\

        )

        /subsystem=infinispan/cache-container=musi/invalidation-cache=configuration/eviction=EVICTION:add(\

        max-entries=1000,\

        strategy=NONE\

        )

        /subsystem=infinispan/cache-container=musi/invalidation-cache=configuration/expiration=EXPIRATION:add(\

        lifespan=3600000,\

        max-idle=-1,\

        interval=-1\

        )

        /subsystem=infinispan/cache-container=musi/invalidation-cache=configuration/transaction=TRANSACTION:add(\

        mode=NONE\

        )

        /subsystem=infinispan/cache-container=musi/invalidation-cache=configuration/locking=LOCKING:add(\

        isolation=READ_COMMITTED\

        )

      end-if

       

      I am able to see the cache under cache container in jboss (Configuration -> Subsystem->Infispan->musi->configuration) and not able to see cache under runtime->subsystems->jndiview -> java/jboss->infispan). but i am not able to inject using @resource in the spring.

       

      Different ways i tried to lookup the cache .

       

      <jee:jndi-lookup id="configurationCache" jndi-name="java:jboss/infinispan/cache/musi/configuration" lookup-on-startup="true" proxy-interface="org.infinispan.Cache"/>

       

      @Resource(lookup = "java:jboss/infinispan/cache/musi/configuration")

      Cache<String,Object> cache ;

       

      Error ::

      Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: infinispan/cache/musi/configuration [Root exception is java.lang.IllegalStateException]

          Caused by: javax.naming.NameNotFoundException: infinispan/cache/musi/configuration [Root exception is java.lang.IllegalStateException]

          Caused by: java.lang.IllegalStateException"},

       

      Please suggest how to inject the cache directly in the spring and how we can see the cache under "runtime->subsystems->jndiview -> java/jboss->infispan->cache"

        • 1. Re: Cache Injection in Spring
          zhurlik

          Hi,

           

          Are you using the same corresponded JNDI name, looks like there are 2 names

          1. infinispan/cache/et/configuration
          2. infinispan/container/musi/configuration

           

          Thanks,

          Vlad

          • 2. Re: Cache Injection in Spring
            siva.munnaluri

            Hi Vlad,

             

            I mentioned wrong container name  .

             

            correct one ::

            1. infinispan/container/musi/configuration

             

            Issue is still persist .

             

            Please suggest what to be done to resolve the injection.

             

            Thanks in advance.

            • 3. Re: Cache Injection in Spring
              zhurlik

              Could you provide <cache-container> from your standalone.xml?

              • 4. Re: Cache Injection in Spring
                siva.munnaluri

                cache container and cache from my standalone.xml

                 

                <cache-container name="musi" default-cache="default" jndi-name="java:jboss/infinispan/container/musi" statistics-enabled="true">

                                <replicated-cache name="configuration" jndi-name="java:jboss/infinispan/container/musi/configuration" mode="SYNC">

                                    <transaction mode="NON_XA"/>

                                    <eviction strategy="LRU" max-entries="1000"/>

                                    <expiration max-idle="600000"/>

                                </replicated-cache>

                            </cache-container>

                 

                I tried to lookup using below jndi

                @Resource(lookup = "java:jboss/infinispan/cache/musi/configuration")

                 

                Above lookup doesn't work so changed to as per suggestion in the google 

                @Resource(lookup = "java:jboss/infinispan/container/musi/configuration")

                 

                Not able to lookup above jndi

                 

                • 5. Re: Cache Injection in Spring
                  zhurlik

                  Could you remove attribute name="jndi-name" for both tags in the standalone.xml

                  This is from jboss-ass-infinspan_4_0.xsd

                  <xs:attribute name="jndi-name" type="xs:string">

                     <xs:annotation>

                     <xs:documentation>

                    The jndi name to which to bind this cache container.

                    If undefined, the cache will be bound to: java:jboss/infinispan/container/container-name

                     </xs:documentation>

                     </xs:annotation>

                  </xs:attribute>

                   

                   

                  After this I am able to get the bean with name 'musiCacheContainer'

                  <jee:jndi-lookup id="musiCacheContainer" jndi-name="java:jboss/infinispan/container/musi"/>

                  • 6. Re: Cache Injection in Spring
                    siva.munnaluri

                    Hi ,

                     

                    We are able to retrieve the container successfully .

                    but not able to lookup the cache using spring

                     

                    @Resource(lookup = "java:jboss/infinispan/container/musi/configuration")

                     

                    And one more thing

                     

                    may i know the significance of jboss-ass-infinspan_4_0.xsd

                     

                    Thanks in advance .

                    • 7. Re: Cache Injection in Spring
                      zhurlik

                      Hi,

                      Looks like the attribute jndi-name doesn't work as expected (perhaps you can create a bug).

                      Because I see the following that it doesn't matter if you specify or not  jndi-name. Every time the JNDI name for the container will be in format as it's described in xsd: java:jboss/infinispan/container/container-name

                      Also I didn't find any caches in the InitialContext, I mean that there are no any caches which are defined in the standalone.xml.

                      I think that right now you have only one way via getting a reference to CacheContainer and retrieving a cache using its methods (it should be enough and easy to do)

                       

                      Thanks,

                      Vlad

                      • 8. Re: Cache Injection in Spring
                        sebastian.laskawiec

                        siva.munnaluri  wrote:

                        may i know the significance of jboss-ass-infinspan_4_0.xsd

                        This one should not really matter.

                        • 9. Re: Cache Injection in Spring
                          zhurlik

                          Maybe, I mentioned about this only because <subsystem xmlns="urn:jboss:domain:infinispan:4.0">  uses this xsd and where I found the description about jndi-name attribute.

                          • 10. Re: Cache Injection in Spring
                            galder.zamarreno

                            Dunno what could be wrong right now, what Infinispan version are you using? Have you tried last release (and pre-release)?

                             

                            If you could attach a reproducer and explain how to reproduce it'd be very helpful.

                            • 11. Re: Cache Injection in Spring
                              pferraro

                              siva.munnaluri Is this a WildFly question? If so, please post to the WildFly forums and specify which version you are talking about.

                              • 12. Re: Cache Injection in Spring
                                siva.munnaluri

                                I am using the 8.1.4.Final version of Infinispan .

                                 

                                I am created a cache along with the cache container in infinispan .( As mentioned above using resouces.cli script and samething is reflecting properly in the standalone.xml) 

                                Able to see the cache and cache container under subsystem of infinispan in jboss ( Spring ) .

                                 

                                Now , I am need to fetch the cache using the jndi lookup as

                                <jee:jndi-lookup id="nativeCacheManager" jndi-name="java:jboss/infinispan/container/musi"/>

                                 

                                but not able to do JNDI lookup of cache manager as below.

                                <jee:jndi-lookup id="configurationCache" jndi-name="java:jboss/infinispan/container/et/category"/>