DevilKing's blog

冷灯看剑,剑上几分功名?炉香无需计苍生,纵一穿烟逝,万丈云埋,孤阳还照古陵

0%

osgi bundle intro

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
@Import(AppConfig.class)
@SpringBootConfiguration
@EnableAutoConfiguration
public class SpringBootBundleActivator implements BundleActivator {

ConfigurableApplicationContext appContext;

@Override
public void start(BundleContext bundleContext) {
Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
appContext = SpringApplication.run(SpringBootBundleActivator.class);
}

@Override
public void stop(BundleContext bundleContext) {
SpringApplication.exit(appContext, () -> 0);
}
}
  • 继承和实现bundleActivator
  • setContextClassLoader部分,可以选择自有的classLoader
  • 采用import的方式,不使用Component scan的方式