2016-04-27 61 views
0

我正在構建一組REST服務並將每個服務部署到單獨的WAR文件。由於每個服務都使用完全相同的持久性配置,因此我將persistence.xml放入了一個jar文件(jar中的persistence.xml文件的路徑仍然是/ META-INF)。如何讓Websphere在jar文件而不是META-INF中找到persistence.xml?

使用TomEE(1.7)運行時,這工作得很好。但是,當我用WebSphere(8.5.5.x)嘗試同樣的事情時,我的持久性單元不會被加載。在WebSphere日誌中,我得到看起來如下錯誤:

[4/27/16 8:54:21:653 EDT] 00000080 JPAApplInfo E CWWJP0029E: The server cannot find the MRO_PU_JTA persistence unit in the Customer_WAR.war module and the DS_APP_EAR application. [4/27/16 8:54:21:654 EDT] 00000080 InjectionBind E CWNEN0035E: The ds.services.helper.AbstractServiceHelper/em reference of type javax.persistence.EntityManager for the component in the Customer_WAR.war module of the DS_APP_EAR application cannot be resolved. [4/27/16 8:54:21:657 EDT] 00000080 ResourceInjec E CWOWB0102E: A JCDI error has occurred: The ds.services.helper.AbstractServiceHelper/em reference of type javax.persistence.EntityManager for the null component in the Customer_WAR.war module of the DS_APP_EAR application cannot be resolved.

當我從我的jar文件到本地WAR的META-INF複製persistence.xml文件,該錯誤消失,一切工作正常。由於我使用這種方式部署了服務,因此我不希望爲每個WAR文件複製persistence.xml。

有沒有辦法讓WebSphere找到我的persistence.xml文件?也許在WebSphere中有一些我一直無法找到的設置?

謝謝。

+0

[在.ear文件中跨組件共享持久性單元]的可能重複(http://stackoverflow.com/questions/4073635/sharing-a-persistence-unit-across-components-in-a-ear-文件) –

回答

1

好了,似乎這是下面的副本:Sharing a persistence unit across components in a .ear file

望着回答從帕斯卡爾Thivent這個問題,它變得相當明顯的問題是什麼:爲了得到這個工作,包含persistence.xml 的jar文件必須位於正在部署到WebSphere的EAR的/ lib目錄中。顯然,它的工作方式是EAR解析persistence.xml文件,並且當每個WAR文件嘗試注入實體管理器時,它會引用EAR來執行此操作。這與TomEE(不使用EAR文件進行部署)相反。在這種情況下,依賴項由WAR文件類加載器解析,因此只需在WAR的類路徑中包含jar文件就足夠了。

相關問題