如何在EAR中的ejb模块和Web模块之间共享Persistence.xml? [英] How to share Persistence.xml between ejb module and web module in EAR?

查看:94
本文介绍了如何在EAR中的ejb模块和Web模块之间共享Persistence.xml?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个EAR应用程序,其中包含一个ejb模块,其中包含所有的enity bean以及很少的会话bean和pojos。它有一个persistence.xml。现在还有其他的web模块是spring mvc app,它在ejb模块中使用实体bean。现在要使用jpa,我必须在web模块中创建一个persistence.xml。但是它已经被复制,因为我们已经在ejb模块中。有没有什么办法可以保留一个persistence.xml,并将在ejb和web模块中使用。有人可以给我简单的项目结构作为例子。只是为了知识,我们正在使用maven。

We have one EAR application with one ejb module which contains all enity beans and few session beans and pojos. It has one persistence.xml. Now there is other web module which is spring mvc app and it uses entity beans in ejb modules. Now to use jpa I have to create one persistence.xml in web module too. But it is duplicated as we already have in ejb module. Is there any way I can keep only one persistence.xml in ear and will be used in both ejb and web module. Can somebody give me simple project structure as an example. Just for knowledge we are using maven.

谢谢

Thanks

推荐答案

<
您可以将您的persistence.xml连同您的实体类一起放入一个单独的jar文件中,并将其放入您的EAR的/ lib文件夹中。


You can put your persistence.xml along with your entity classes into a separate jar that you put in the /lib folder of you EAR.

yourEar.ear
    |
    |_ yourEjb.jar
    |
    |_ yourWeb.war
    |
    |_ lib
        |
        |_ yourPersistence.jar
               |
               |_ META-INF/persistence.xml
               |
               |_ yourEntity.class

这篇关于如何在EAR中的ejb模块和Web模块之间共享Persistence.xml?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆