Issue Details (XML | Word | Printable)

Key: SPR-5324
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Juergen Hoeller
Reporter: Jeremy Haile
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
Spring Framework

AnnotationSessionFactoryBean.scanPackages() creates scanning pattern incorrectly

Created: 26/Nov/08 12:47 PM   Updated: 26/Aug/09 07:25 AM   Resolved: 28/Nov/08 08:05 AM
Component/s: None
Affects Version/s: 2.5.6
Fix Version/s: 3.0 M1

Time Tracking:
Not Specified

Issue Links:
Duplicate
 

Virtual Machine: Sun JVM - 1.6
Platform: Tomcat - 6.0


 Description  « Hide

The "scanPackages" property requires the package name to have a trailing "." which is inconsistent with the component-scan. This feature was adding by SPR-4738

ClassPathScanningCandidateComponentProvider (used by component-scan) constructs the scanning pattern like this:
String packageSearchPath = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + resolveBasePackage(basePackage) + "/" + this.resourcePattern;

AnnotationSessionFactoryBean constructs the scanning pattern like this:
String pattern = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + ClassUtils.convertClassNameToResourcePath(pkg) + RESOURCE_PATTERN;

Notice the missing "/" in the hibernate class. This means that the resource pattern is constructed like classpath*:myPackage*/.class instead of classpath*:myPackage/*/.class

This works when all persistence classes are in the package to be scanned, but fails to scan subclasses. AnnotationSessionFactoryBean should be changed to construct its pattern like component-scan does.

A workaround is to append a trailing "." onto the end of your package name.



Jeremy Haile added a comment - 26/Nov/08 01:00 PM

I meant "fails to scan subpackages", not "fails to scan subclasses"


Juergen Hoeller added a comment - 28/Nov/08 08:05 AM

Indeed - thanks for pointing this out!

Juergen