diff --git a/com.creditease.uav.monitorframework/src/main/java/com/creditease/uav/profiling/handlers/ComponentProfileHandler.java b/com.creditease.uav.monitorframework/src/main/java/com/creditease/uav/profiling/handlers/ComponentProfileHandler.java index b3105b02..cfc08c2d 100644 --- a/com.creditease.uav.monitorframework/src/main/java/com/creditease/uav/profiling/handlers/ComponentProfileHandler.java +++ b/com.creditease.uav.monitorframework/src/main/java/com/creditease/uav/profiling/handlers/ComponentProfileHandler.java @@ -698,7 +698,7 @@ public boolean parse(DescriptorCollector dc, Node node) { String[] paths = StringHelper.tokenizeToStringArray(springConfigLocations.get(0), CONFIG_LOCATION_DELIMITERS); for (String path : paths) { - files.addAll(getFileLocation(webAppRoot, path)); + files.addAll(getFileLocation(webAppRoot, path, null)); } } @@ -732,7 +732,7 @@ public boolean parse(DescriptorCollector dc, Node node) { String importFileRelativePath = importFilePathPart1 + "/" + importFilePathPart2; - importfile.addAll(getFileLocation(webAppRoot, importFileRelativePath)); + importfile.addAll(getFileLocation(webAppRoot, importFileRelativePath, importFilePathPart2)); } } catch (IOException e) { @@ -945,7 +945,8 @@ private String getImplClassAsKey(String key, Node jaxws, ClassLoader cl, String * @param filepath * @return */ - private List getFileLocation(String webAppRoot, String path) { + @SuppressWarnings({ "unchecked", "rawtypes" }) + private List getFileLocation(String webAppRoot, String path, String importFilePathPart2) { List absPaths = new ArrayList(); ClassLoader webappclsLoader = (ClassLoader) this.getContext().get(InterceptContext.class) @@ -979,6 +980,20 @@ private List getFileLocation(String webAppRoot, String path) { File location = null; if (resources != null) { + if (importFilePathPart2 != null) { + try { + // spring: if resource belongs to ClassPathResource or its subclass, try loading "org.springframework.core.io.ClassPathResource" and get resources again, + // in case that files cannot be found in relative path "path". + Class cpRes = webappclsLoader.loadClass("org.springframework.core.io.ClassPathResource"); + if(cpRes != null && cpRes.isAssignableFrom(resources[0].getClass())) { + resources = (Object[]) ReflectionHelper.invoke(SPRING_ResourcePatternResolver_CLASSNAME, resourceloader, + "getResources", new Class[] { String.class }, new String[] { importFilePathPart2 }, webappclsLoader); + } + } + catch (ClassNotFoundException e1) { + // ignore + } + } for (Object resource : resources) { try { location = (File) ReflectionHelper.invoke(SPRING_RESOURCE_CLASSNAME, resource, "getFile", null,