简体   繁体   中英

inject infinispan cache into wildfly 8.0.0.Final

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

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>

that produces in my MANIFEST.MF

Dependencies: org.infinispan.commons export

When i use the getCache() method i have java.lang.NullPointerException because the myCacheManager attribute is null. Looking in the JNDI Bindings tab in the administration console I noticed that, while there are many other resources defined by me like datasources, there's no resource corresponding to "java:jboss/infinispan/container/my-cache" (that I supposed to be the default path). I also tryed to specify the jndi name in the cache container definition, with the same results.

Where I am wrong? Thanks in advance

Use

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

instead of below

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

This will give your cache container and also add dependencies org.infinispan export in META-INF

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM