我正在构建一组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中有一些我一直无法找到的设置?
谢谢。
[在.ear文件中跨组件共享持久性单元]的可能重复(http://stackoverflow.com/questions/4073635/sharing-a-persistence-unit-across-components-in-a-ear-文件) –