简体   繁体   English

将infinispan缓存注入wildfly 8.0.0.Final

[英]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. 我试图在我的应用程序中使用infinispan(6.0)部署在wildfly 8.0.0.Final中的独立配置(jdk 1.7),但是我在注入方面遇到了一些问题。 Starting from this post and searching on google I had this sistuation: 这篇文章开始并在谷歌搜索我有这个sistuation:

In standalone.xml 在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 最后在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 在我的MANIFEST.MF中产生

Dependencies: org.infinispan.commons export

When i use the getCache() method i have java.lang.NullPointerException because the myCacheManager attribute is null. 当我使用getCache()方法时,我有java.lang.NullPointerException,因为myCacheManager属性为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). 查看管理控制台中的JNDI Bindings选项卡,我注意到,虽然我定义了许多其他资源,如数据源,但没有与“java:jboss / infinispan / container / my-cache”对应的资源(我应该是默认路径)。 I also tryed to specify the jndi name in the cache container definition, with the same results. 我还尝试在缓存容器定义中指定jndi名称,结果相同。

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 这将为您的缓存容器提供,并在META-INF中添加依赖项org.infinispan export

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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