LTSXmlApplicationContext.java
1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package com.github.ltsopensource.startup.tasktracker;
import com.github.ltsopensource.core.logger.Logger;
import com.github.ltsopensource.core.logger.LoggerFactory;
import org.springframework.context.support.AbstractXmlApplicationContext;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* @author Robert HG (254963746@qq.com) on 9/12/15.
*/
public class LTSXmlApplicationContext extends AbstractXmlApplicationContext {
private static final Logger LOGGER = LoggerFactory.getLogger(LTSXmlApplicationContext.class);
private Resource[] configResources;
public LTSXmlApplicationContext(String[] paths) {
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
List<Resource> resourceList = new ArrayList<Resource>();
if (paths != null && paths.length > 0) {
for (String path : paths) {
try {
Resource[] resources = resolver.getResources(path);
if (resources != null && resources.length > 0) {
Collections.addAll(resourceList, resources);
}
} catch (IOException e) {
LOGGER.error("resolve resource error: [path={}]", path, e);
}
}
}
configResources = new Resource[resourceList.size()];
resourceList.toArray(configResources);
refresh();
}
@Override
protected Resource[] getConfigResources() {
return configResources;
}
}