6

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}"/>
Noam Nevo
  • 3,021
  • 10
  • 35
  • 49

3 Answers3

8

Look for: http://static.springsource.org/spring/docs/2.5.x/api/org/springframework/orm/hibernate3/annotation/AnnotationSessionFactoryBean.html

the second example:

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
  <property name="dataSource" ref="dataSource"/>
  <property name="packagesToScan" value="test.package"/>
</bean>

Put two wildcards behind to scan all subpackages. (ex: "test.package.**")

SvBu
  • 81
  • 1
  • 1
  • For Hibernate 4: org.springframework.orm.hibernate4.LocalSessionFactoryBean does the job :) – Tobias Aug 03 '14 at 15:45
6

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>
axtavt
  • 239,438
  • 41
  • 511
  • 482
1

use spring3.1,or use <class>com.***.***<class>tag to add entity class in your persistence.xml.

kangcunhua
  • 11
  • 1