如何使用 XML 配置将多个包传递到 Spring 中的 packagesToScan 属性

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26886843/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 00:12:09  来源:igfitidea点击:

How to Pass Multiple Packages to packagesToScan property in Spring using XML Configuration

springspring-orm

提问by Ranga Reddy

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

假设我在称为M1 (com.test1) 和M2(com.test2) 的不同模块中有两个包com.test1com.test2

Now in the following example i configured module1package.

现在在以下示例中,我配置了module1包。

<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 packagesToScanproperty. How to configure.

但我想在packagesToScan属性中配置 Module2 包。如何配置。

回答by Ranga Reddy

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>