<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">启动位置</span>
com.alibaba.dubbo.container.Main.main(String[])
启动前初始化容器loader
private static final ExtensionLoader<Container> loader = ExtensionLoader.getExtensionLoader(Container.class);
读启动配置
在配置文件中读key为"dubbo.container"的内容,如果没有默认为loader的默认扩展名(即Container类的@SPI(value="spring"))
String config = ConfigUtils.getProperty(CONTAINER_KEY, loader.getDefaultExtensionName());
实例化容器
for (int i = 0; i < args.length; i ++) {
containers.add(loader.getExtension(args[i]));
}
启动容器
for (Container container : containers) {
container.start();
logger.info("Dubbo " + container.getClass().getSimpleName() + " started!");
}
spring容器启动 com.alibaba.dubbo.container.spring.SpringContainer.start()
读配置文件中“dubbo.spring.config”作为配置文件的地址,如果没有配置默认地址为:classpath*:META-INF/spring/*.xml
启动spring容器
public void start() {
String configPath = ConfigUtils.getProperty(SPRING_CONFIG);
if (configPath == null || configPath.length() == 0) {
configPath = DEFAULT_SPRING_CONFIG;
}
context = new ClassPathXmlApplicationContext(configPath.split("[,\\s]+"));
context.start();
}
主循环
synchronized (Main.class) {
while (running) {
try {
Main.class.wait();
} catch (Throwable e) {
}
}
}
关闭hook
Runtime.getRuntime().addShutdownHook(new Thread() {
public void run() {
for (Container container : containers) {
try {
container.stop();
logger.info("Dubbo " + container.getClass().getSimpleName() + " stopped!");
} catch (Throwable t) {
logger.error(t.getMessage(), t);
}
synchronized (Main.class) {
running = false;
Main.class.notify();
}
}
}
});