1
1
/*
2
- * Copyright 2002-2012 the original author or authors.
2
+ * Copyright 2002-2013 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -79,6 +79,8 @@ public class AnnotationSessionFactoryBean extends LocalSessionFactoryBean implem
79
79
80
80
private static final String RESOURCE_PATTERN = "/**/*.class" ;
81
81
82
+ private static final String PACKAGE_INFO_SUFFIX = ".package-info" ;
83
+
82
84
83
85
private Class [] annotatedClasses ;
84
86
@@ -101,7 +103,7 @@ public AnnotationSessionFactoryBean() {
101
103
102
104
103
105
@ Override
104
- public void setConfigurationClass (Class configurationClass ) {
106
+ public void setConfigurationClass (Class <?> configurationClass ) {
105
107
if (configurationClass == null || !AnnotationConfiguration .class .isAssignableFrom (configurationClass )) {
106
108
throw new IllegalArgumentException (
107
109
"AnnotationSessionFactoryBean only supports AnnotationConfiguration or subclasses" );
@@ -191,9 +193,12 @@ protected void scanPackages(AnnotationConfiguration config) {
191
193
if (resource .isReadable ()) {
192
194
MetadataReader reader = readerFactory .getMetadataReader (resource );
193
195
String className = reader .getClassMetadata ().getClassName ();
194
- if (matchesFilter (reader , readerFactory )) {
196
+ if (matchesEntityTypeFilter (reader , readerFactory )) {
195
197
config .addAnnotatedClass (this .resourcePatternResolver .getClassLoader ().loadClass (className ));
196
198
}
199
+ else if (className .endsWith (PACKAGE_INFO_SUFFIX )) {
200
+ config .addPackage (className .substring (0 , className .length () - PACKAGE_INFO_SUFFIX .length ()));
201
+ }
197
202
}
198
203
}
199
204
}
@@ -211,7 +216,7 @@ protected void scanPackages(AnnotationConfiguration config) {
211
216
* Check whether any of the configured entity type filters matches
212
217
* the current class descriptor contained in the metadata reader.
213
218
*/
214
- private boolean matchesFilter (MetadataReader reader , MetadataReaderFactory readerFactory ) throws IOException {
219
+ private boolean matchesEntityTypeFilter (MetadataReader reader , MetadataReaderFactory readerFactory ) throws IOException {
215
220
if (this .entityTypeFilters != null ) {
216
221
for (TypeFilter filter : this .entityTypeFilters ) {
217
222
if (filter .match (reader , readerFactory )) {
0 commit comments