59866: When scanning WEB-INF/classes for annotations, don't scan the contents of WEB-INF/classes/META-INF (if present) since classes will never be loaded from that location. (markt)
대상 버전 : Tomcat 7.0.71 ~ 등
- 9.0.x for 9.0.0.M10 onwards
- 8.5.x for 8.5.5 onwards
- 8.0.x for 8.0.37 onwards
- 7.0.x for 7.0.71 onwards
1. ContextConfig
WebConfig 메소드 내에 else if ("META-INF".equals(binding.getName())) 부분 추가입니다. (아래 확인)
try {
try {
listBindings = context.getResources().listBindings(
"/WEB-INF/classes");
} catch (NameNotFoundException ignore) {
// Safe to ignore
}
while (listBindings != null &&
listBindings.hasMoreElements()) {
Binding binding = listBindings.nextElement();
if (binding.getObject() instanceof FileDirContext) {
File webInfClassDir = new File(
((FileDirContext) binding.getObject()).getDocBase());
processAnnotationsFile(webInfClassDir, webXml,
webXml.isMetadataComplete());
} else if ("META-INF".equals(binding.getName())) {
// Skip the META-INF directory from any JARs that have been
// expanded in to WEB-INF/classes (sometimes IDEs do this).
} else {
String resource =
"/WEB-INF/classes/" + binding.getName();
try {
URL url = sContext.getResource(resource);
processAnnotationsUrl(url, webXml,
webXml.isMetadataComplete());
} catch (MalformedURLException e) {
log.error(sm.getString(
"contextConfig.webinfClassesUrl",
resource), e);
}
}
}
} catch (NamingException e) {
log.error(sm.getString(
"contextConfig.webinfClassesUrl",
"/WEB-INF/classes"), e);
}
}
2. BaseDirContext
if (name.endsWith(".class")) 로직 추가입니다.
private Object doLookupWithoutNNFE(String name) throws NamingException {
if (!aliases.isEmpty()) {
AliasResult result = findAlias(name);
if (result.dirContext != null) {
return result.dirContext.lookup(result.aliasName);
}
}
// Next do a standard lookup
Object obj = doLookup(name);
if (obj != null) {
return obj;
}
// Class files may not be loaded from the alternate locations so don't
// waste cycles looking.
if (name.endsWith(".class")) {
return null;
}
// Check the alternate locations (Resource JARs)
String resourceName = "/META-INF/resources" + name;
for (DirContext altDirContext : altDirContexts) {
if (altDirContext instanceof BaseDirContext) {
obj = ((BaseDirContext) altDirContext)
.doLookupWithoutNNFE(resourceName);
} else {
try {
obj = altDirContext.lookup(resourceName);
} catch (NamingException ex) {
// ignore
}
}
if (obj != null) {
return obj;
}
}
// Return null instead
return null;
}