2016-04-27 47 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文件就足够了。

相关问题