PackageToScan使用详解【Spring集成Hibernate时使用annotation形式的pojo对象时的映射类的扫描问题】

I am doing the same thing and ran into the same problem. As far as I can tell packagesToScan will take a list of packages and only scan for entities in those packages, not subpackages.

I did have some success with the wildcard "*". Using an example class structure I will explain what I saw and what my solution was:
com.model.Entity1
com.model.Entity2
com.model.foo.Entity3
com.model.bar.Entity4
com.model.foo.bar.Entity5
com.model.bar.foo.Entity6

My solution for this structure was:
<property name="packagesToScan">
<list>
<value>com.model</value>
<value>com.model.*</value>
<value>com.model.*.*</value>
</list>
</property>

com.model would find Entity1 and Entity2 and only those entities
com.model.* would find Entity3 and Entity4 and only those entities
com.model.*.* would find Entity5 and Entity6 and only those entities

I haven't looked at the source code. I thought it would just be easier to play with it and see what it does. 

I think it would be nice if you could specify a .** to recurse through all subpackages. I don't know if the * is getting expanded by whatever parses the config or if the AnnotationSessionFactoryBean is supporting this.

 

Hi drob,

thanks a lot for your answer. I think I found a solution, at least in my case. I just use this syntax:

Code:
<property name="packagesToScan">
	<list>
		<value>de.moose.r2.domain.**.*</value>
	</list>
</property>

Now every entity-class, even in sub-packages, will be found by spring.

Hope that helps

<贴自:http://forum.springsource.org/showthread.php?76050-AnnotationSessionFactoryBean-packagesToScan-scanning-of-sub-packages>

 

 

 

  1. <!--  
  2.     packagesToScan的路径配置要比实际的少一层,  
  3.     此处的pojo放在cn.com.easykm.commonkey.entity包里面  
  4.     但是配置的却是cn.com.easykm.commonkey.*  
  5. -->  
  6. <list>  
  7.     <value>cn.com.easykm.commonkey.*  
  8.     </value>  
  9. </list>  

你可能感兴趣的:(annotation)