【发布时间】:2009-04-03 11:42:48
【问题描述】:
所以我有一个 spring 应用程序分为几个模块,每个模块都在一个单独的项目中。 每个模块都有自己的 JPA 实体,我使用 Spring ORM 进行配置:
<beans ...>
<context:component-scan
base-package="org.myapp.module1.persistence" />
<context:component-scan
base-package="org.myapp.module2.persistence" />
...
<context:annotation-config />
<tx:annotation-driven />
...
</beans>
persistence.xml 文件如下所示:
<persistence ...>
<persistence-unit name="myunit" />
</persistence>
我的问题是,当 Spring 上下文初始化时,它只会在 persistence.xml 文件的同一路径上查找 @Entity 类,而忽略其他项目的类路径。
我尝试拥有多个persistence.xml,每个都与@Entity 类在同一路径中,但在这种情况下,一旦Spring 找到第一个persistence.xml,它就会停止加载并且不会在其他路径上找到任何@Entity 类.
如何让 Spring 查看所有内容?
【问题讨论】: