bundle A 加載osgi context中所有bundle的
application文件夾下.properties的鍵值對方法
private static String CONFIG_PATH = "configuration";
private static String FilePattern = "*.properties";
public void init() throws Exception {
Bundle[] bds = bundle.getBundleContext().getBundles();
for (Bundle b : bds) {
Enumeration<URL> e = b.findEntries(CONFIG_PATH, FilePattern, true);
if (e != null) {
while (e.hasMoreElements()) {
URL url = e.nextElement();
if (url != null) {
InputStream in = url.openStream();
try {
properties.load(in);
} finally {
in.close();
}
}
}
}
}
}
Activator.context = bundleContext;
Bundle bundle = context.getBundle();
String bundleName = bundle.getSymbolicName();
FrameworkPropertyHolder propertyHolder = new FrameworkPropertyHolder();
propertyHolder.setBundle(bundle);
propertyHolder.init();
osgi繼承spring後,啓動spring容器時,在配置文件中,需要解析通配符${xxx.name}.