24

Assume i have two packages com.test1 and com.test2 in different modules called M1 (com.test1) and M2 (com.test2).

Now in the following example i configured module1 package.

<bean id="entityManager" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">        
       <property name="packagesToScan" value="com.test1" />
       <property name="dataSource" ref="dataSource" />
       <property name="jpaVendorAdapter" ref="hibernateVendor" />
       <property name="jpaPropertyMap" ref="jpaPropertyMap" />
   </bean>

But i want to configure Module2 package as well in packagesToScan property. How to configure.

Jens Schauder
  • 65,795
  • 24
  • 148
  • 294
Ranga Reddy
  • 2,433
  • 3
  • 26
  • 34

1 Answers1

38

I found answer my self.

<bean id="entityManager" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">        
     <property name="packagesToScan">
         <array>
              <value>com.test1</value>
              <value>com.test2</value>
         </array>
     </property>       
     <property name="dataSource" ref="dataSource" />
     <property name="jpaVendorAdapter" ref="hibernateVendor" />
     <property name="jpaPropertyMap" ref="jpaPropertyMap" />
</bean>
Ranga Reddy
  • 2,433
  • 3
  • 26
  • 34
  • 3
    The javadoc for packagesToScan says: `packagesToScan one or more base packages to search, analogous to Spring's component-scan configuration for regular Spring components`, which implies that comma/semicolon/space/tab/linefeed-separated packages should also work. – Dormouse May 26 '16 at 08:46
  • 2
    That appears to be correct, @Dormouse. I tested this with comma-separated packages and it works for me. – DavidS Jan 25 '17 at 00:39
  • Awesome Example Reddy. – Lova Chittumuri Nov 06 '17 at 13:35