Hibernate - 弹簧注释的实体不从jar中扫描 [英] Hibernate - spring annotated entities not scanned from within jar
问题描述
我有一个包含注释实体类的包,我将其导入到我的Web项目中。
当tomcat部署该项目时,jar中的实体类不会被扫描注释。有没有办法告诉spring在jar文件中搜索带注释的类?即:
< context:component-scan base-package ={jar to jar的路径}/>
如果您的意思是 @Entity
注释类,< context:component-scan>
与它们无关。 @Entity
类是由Hibernate发现的,所以你需要配置Hibernate,而不是Spring。
如果您通过JPA使用Hibernate(即您有 persistence.xml
),则需要添加以下行为了扫描实体类的 /WEB-INF/lib/yourFileWithEntities.jar
: persistence.xml p>
< jar-file> lib / yourFileWithEntities.jar< / jar-file>
I have a package containing annotated entity classes that I import into my web project. When tomcat deploys the project the entity class that are in the jar are not scanned for annotations. is there a way to tell spring to search for annotated classes inside a jar file? i.e. :
<context:component-scan base-package="{path to jar or something}"/>
If you mean @Entity
annotated classes, <context:component-scan>
has nothing to do with them. @Entity
classes are discovered by Hibernate, so you need to configure Hibernate, not Spring.
If you use Hibernate via JPA (i.e. you have persistence.xml
), you need to add the following line to persistence.xml
in order to scan /WEB-INF/lib/yourFileWithEntities.jar
for entity classes:
<jar-file>lib/yourFileWithEntities.jar</jar-file>
这篇关于Hibernate - 弹簧注释的实体不从jar中扫描的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!