#444 - Spring Boot classpath scanning not finding entity beans

This commit is contained in:
Robin Bygrave
2015-10-28 15:45:09 +13:00
parent 67c711d75f
commit 848a3b8888
2 changed files with 23 additions and 11 deletions
@@ -157,7 +157,7 @@ public class ClassPathSearch implements ClassPathSearchService {
} else if (element.isJarOrWar()) {
// search name including the ! offset if it is there
if (classPathSize == 1 || filter.isSearchJar(element.getJarNameWithOffset())) {
if (classPathSize == 1 || filter.isSearchJar(element.getJarNameWithOffset(), element.getJarOffset())) {
scanJar(element);
}
@@ -234,6 +234,8 @@ public class ClassPathSearch implements ClassPathSearchService {
File file = classPathEntry.classPath;
module = new JarFile(file);
logger.trace("scanJar file:{}", file);
List<URI> classPathFromManifest = getClassPathFromManifest(file, module.getManifest());
for (URI uri : classPathFromManifest) {
scanUri(uri);
@@ -303,7 +305,11 @@ public class ClassPathSearch implements ClassPathSearchService {
* prefix. We want to come out with a name like WEB-INF/classes/ to ensure
* we filter the contents of the war/jar file by this.
*/
if (jarOffset != null) {
if ("/".equals(jarOffset)) {
// root level for runnable jar (spring boot etc)
jarOffset = null;
} else if (jarOffset != null) {
if (jarOffset.startsWith("/")) {
jarOffset = jarOffset.substring(1);
}
@@ -498,6 +504,10 @@ public class ClassPathSearch implements ClassPathSearchService {
String getJarNameWithOffset() {
return (jarOffset == null) ? classPath.getName() : classPath.getName() + "!" + jarOffset;
}
String getJarOffset() {
return jarOffset;
}
}
}
@@ -122,17 +122,19 @@ public class ClassPathSearchFilter {
/**
* Return true if the jar should be included in the search.
*/
public boolean isSearchJar(String jarName) {
public boolean isSearchJar(String jarName, String jarOffset) {
if (containedIn(includeJarSet, jarName)) {
return true;
}
if (containedIn(includeJarSet, jarName)) {
return true;
}
if (containedIn(excludeJarSet, jarName)) {
return false;
}
return defaultJarMatch;
}
if (containedIn(excludeJarSet, jarName)) {
return false;
}
// by default scan the root level in runnable jar (spring boot etc)
return "/".equals(jarOffset) || defaultJarMatch;
}
/**
* Helper method to determine is a match is contained in the set.