如何配置Wildfly 8以将Infinispan用于缓存实体

时间:2014-08-06 11:36:33

标签: java caching jboss infinispan

我正在尝试创建一个本地infinispan缓存,我知道它需要在wildfly的config.xml中进行更改。我尝试这样做,当我尝试访问该缓存时,它显示缓存不可用。我不知道我做错了什么,有人可以帮我这个。

config.xml中的更改

         <subsystem xmlns="urn:jboss:domain:infinispan:2.0">

         <cache-container name="web" aliases="standard-session-cache" default-cache="local-web" module="org.wildfly.clustering.web.infinispan">

         </cache-container>
         <cache-container name="hibernate" default-cache="local-query" module="org.hibernate">

         </cache-container>
    //This is my local cache
       <cache-container name="myCache" default-cache="cachedb">
       <local-cache name="cachedb"/>
       </cache-container>
        </subsystem>

以下是访问缓存的代码

        @Stateless 
        public class SimpleCache {

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

         private org.infinispan.Cache<String, String> cache;
        @PostConstruct
         public void initCache() {
          this.cache = container.getCache();
         }

         public String get(String key) {
          return this.cache.get(key);
         }

         public void put(String key, String value) {
          this.cache.put(key, value);
         }

        }

错误:

java:global/InfinispanTest/SimpleCache!SimpleCache
    java:app/InfinispanTest/SimpleCache!SimpleCache
    java:module/SimpleCache!SimpleCache
    java:global/InfinispanTest/SimpleCache
    java:app/InfinispanTest/SimpleCache
    java:module/SimpleCache

17:05:09,721 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS015870: Deploy of deployment "InfinispanTest.war" was rolled back with failure message {"JBAS014771: Services with missing/unavailable dependencies" => ["jboss.naming.context.java.module.InfinispanTest.InfinispanTest.env.SimpleCache.containerjboss.naming.context.java.jboss.infinispan.container.myCacheMissing[jboss.naming.context.java.module.InfinispanTest.InfinispanTest.env.SimpleCache.containerjboss.naming.context.java.jboss.infinispan.container.myCache]"]}
17:05:09,769 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-4) JBAS015877: Stopped deployment InfinispanTest.war in 45ms
17:05:09,770 INFO  [org.jboss.as.controller] (DeploymentScanner-threads - 2) JBAS014774: Service status report
JBAS014775:    New missing/unsatisfied dependencies:
      service jboss.naming.context.java.jboss.infinispan.container.myCache (missing) dependents: [service jboss.naming.context.java.module.InfinispanTest.InfinispanTest.env.SimpleCache.container] 

17:05:09,772 ERROR [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) {"JBAS014653: Composite operation failed and was rolled back. Steps that failed:" => {"Operation step-2" => {"JBAS014771: Services with missing/unavailable dependencies" => ["jboss.naming.context.java.module.InfinispanTest.InfinispanTest.env.SimpleCache.containerjboss.naming.context.java.jboss.infinispan.container.myCacheMissing[jboss.naming.context.java.module.InfinispanTest.InfinispanTest.env.SimpleCache.containerjboss.naming.context.java.jboss.infinispan.container.myCache]"]}}}

1 个答案:

答案 0 :(得分:1)

您是否在项目中加入了infinispan依赖项?

加入META_INF / MANIFEST.MF:

dependencies: org.infinispan export