我有一个包含注释实体类的包,我将其导入到我的Web项目中.当tomcat部署项目时,不会扫描jar中的实体类以进行注释.有没有办法告诉spring在jar文件中搜索带注释的类?即:
<context:component-scan base-package="{path to jar or something}"/>
Run Code Online (Sandbox Code Playgroud)
小智 8
寻找:http: //static.springsource.org/spring/docs/2.5.x/api/org/springframework/orm/hibernate3/annotation/AnnotationSessionFactoryBean.html
第二个例子:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="packagesToScan" value="test.package"/>
</bean>Run Code Online (Sandbox Code Playgroud)
将两个通配符放在后面以扫描所有子包.(例如:"test.package.**")
如果您的意思是@Entity注释类,<context:component-scan>则与它们无关.@EntityHibernate发现了类,所以你需要配置Hibernate,而不是Spring.
如果你通过JPA使用Hibernate(即你有persistence.xml),你需要添加以下行persistence.xml来扫描/WEB-INF/lib/yourFileWithEntities.jar实体类:
<jar-file>lib/yourFileWithEntities.jar</jar-file>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11746 次 |
| 最近记录: |