Inject infinite cache in wildfly 8.0.0.Final

I am trying to use infinispan (6.0) from my application deployed to wildfly 8.0.0.Final in standalone configuration (jdk 1.7) but I have some injection problems. Starting with this post and searching on google, I had this setup:

In standalone.xml

        <subsystem xmlns="urn:jboss:domain:infinispan:2.0">
            ...
            <cache-container name="my-cache" default-cache="my-cache-default">
                <local-cache name="my-cache-default">
                </local-cache>
            </cache-container>
        </subsystem>

      

and

public class CacheManager {

    @Resource(lookup="java:jboss/infinispan/container/my-cache")
    private EmbeddedCacheManager myCacheManager;

    public Cache<String, String> getCache() {
        return myCacheManager.getCache();
    }
}

      

Finally in the pom.xml

<build>
    <finalName>${project.artifactId}</finalName>
    <plugins>
        <plugin>
            <artifactId>maven-ejb-plugin</artifactId>
            <version>${version.ejb.plugin}</version>
            <configuration>
                ...
                <archive>
                    <manifestEntries>
                        <Dependencies>org.infinispan.commons export</Dependencies>
                    </manifestEntries>
                </archive>
            </configuration>
        </plugin>
    </plugins>
</build>

      

which is generated in my MANIFEST.MF

Dependencies: org.infinispan.commons export

      

When I use the getCache () method, I have a java.lang.NullPointerException because the myCacheManager attribute is NULL. Looking at the JNDI Bindings tab in the admin console I noticed that while there are many other resources for me like datasources, there is no resource corresponding to "java: jboss / infinispan / container / my-cache" (which I should have been path default). I also tried specifying the jndi name in the cache container definition with the same results.

Where am I going wrong? thanks in advance

+3


source to share


1 answer


Use

@Resource(lookup="java:jboss/infinispan/container/my-cache") private CacheContainer container;

instead



@Resource(lookup="java:jboss/infinispan/container/my-cache") private EmbeddedCacheManager myCacheManager;

This will give you a cache container and also add org.infinispan export dependencies to META-INF

+1


source







All Articles