/**
* @param componentsConfig
* @param servletContext2
* @return
*/
private Map<String, String> findComponents(
ComponentsConfig componentsConfig, ServletContext servletContext) {
String locationPattern = componentsConfig.getDiscoveryLocationPattern();
String[] prefixAndPattern = checkComponentConfigurationLocationPattern(locationPattern);
String prefix = prefixAndPattern[0];
String pathPattern = prefixAndPattern[1];
Map<String, String> componentNamesAndLocations = new TreeMap<String, String>();
if(componentsConfig.isAutoDiscovery()){
try {
ResourcePatternResolver resolver = new ServletContextResourcePatternResolver(servletContext);
Resource[] componentConfigurations = resolver.getResources(locationPattern);
Pattern pattern = PathNameWildcardCompiler.compilePathName(pathPattern);
if (componentConfigurations != null) {
for (Resource resource : componentConfigurations) {
String path = resource.getURL().getPath();
Matcher matcher = pattern.matcher(path);
Assert.assertTrue(matcher.find(), "unknown component configuration file: %s", path);
String componentName = StringUtils.trimToNull(matcher.group(1));
if (componentName != null) {
componentNamesAndLocations.put(componentName,
prefix + pathPattern.replace("*", componentName));
}
}
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return componentNamesAndLocations;
}
WmixContextLoaderListener.java 文件源码
java
阅读 18
收藏 0
点赞 0
评论 0
项目:wmix
作者:
评论列表
文章目录