2013-12-07 64 views
2

在將正在工作的EAR應用程序遷移到JBoss AS 7.1.1-Finel的過程中,我遇到了另一個我無法解決的問題。不久之後,EJB3將查找緩存容器並在其中存儲數據。訪問Infinispan緩存容器失敗

org.infinispan.manager.CacheContainer container = null; 
... 
public static CacheContainer getCacheContainer() { 
    if(container == null) { 
     try { 
      Context ctx = new InitialContext(); 
      container = (CacheContainer) ctx 
        .lookup("java:jboss/infinispan/container/mycache"); 
     } catch (NamingException e) { 
      e.getCause(); 
     } 
    } 
    return container; 
} 

耳朵定義了在JBoss部署-structure.xml Infinispan的依賴,以這樣的方式

<jboss-deployment-structure> 
    <deployment> 
     <dependencies> 
      <module name="org.hibernate" slot="main" /> 
      <module name="org.infinispan" slot="main" /> 
      <module name="org.jboss.as.clustering.infinispan" /> 
     </dependencies> 
    </deployment> 
</jboss-deployment-structure> 

當我部署此代碼,我得到以下錯誤:

Caused by: java.lang.NoClassDefFoundError: org/infinispan/manager/CacheContainer 

有人能幫助我嗎?

最好的問候, SK

回答

2

這將僅適用於頂級的部署工作,因爲描述here。您可能需要將org.infinispan依賴移動到相關sub-deployment部分:

<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2"> 
    ... 
    <!-- This corresponds to the top level deployment. For a war this is the war's module, for an ear --> 
    <!-- This is the top level ear module, which contains all the classes in the EAR's lib folder  --> 
    <deployment> 
    <dependencies> 
     ... 
    </dependencies> 
    </deployment> 
    <sub-deployment name="myapp.war"> 
    <!-- This corresponds to the module for a web deployment --> 
    <!-- it can use all the same tags as the <deployment> entry above --> 
    <dependencies> 
     <module name="org.infinispan" slot="main" /> 
    </dependencies> 
    </sub-deployment> 
    ... 
</jboss-deployment-structure> 
+0

謝謝Szymon,是解決我的問題。 –

+0

謝謝,這非常有幫助。但是,不應該將其作爲全球依賴項,例如就像我們用org.hibernate.commons-annotations等?您鏈接的文檔中說,部署依賴關係是全局的,就像它們被添加到清單中一樣(這正是Infinispan文檔所建議的)。對此有何想法? – Thomas

+0

@Thomas我不確定我是否理解正確,但是如果您指的是_Global Modules_部分,那麼是的 - 它也應該在該級別上工作。但請記住,這與'jboss-deployment-structure.xml'不相關,因爲''部分放在應用服務器配置中(例如'standalone.xml'),而不是部署描述符本身。 –