下面列出了org.springframework.context.ConfigurableApplicationContext#registerShutdownHook ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void refreshContext(ConfigurableApplicationContext context) {
refresh(context);
if (this.registerShutdownHook) {
try {
context.registerShutdownHook();
}
catch (AccessControlException ex) {
// Not allowed in some environments.
}
}
}
/**
* @inheritDoc
*/
@Override
public ApplicationContext loadContext(MergedContextConfiguration mergedConfig) {
ConfigurableApplicationContext applicationContext =
configure(newApplicationContext(mergedConfig), mergedConfig);
applicationContext.registerShutdownHook();
applicationContext.refresh();
return applicationContext;
}
/**
* Obtain an ApplicationContext for the given key, potentially cached.
* @param locations the context key; may be {@code null}.
* @return the corresponding ApplicationContext instance (potentially cached),
* or {@code null} if the provided {@code key} is <em>empty</em>
*/
protected final ConfigurableApplicationContext getContext(String... locations) throws Exception {
if (ObjectUtils.isEmpty(locations)) {
return null;
}
String key = contextKey(locations);
ConfigurableApplicationContext ctx = contextKeyToContextMap.get(key);
if (ctx == null) {
ctx = loadContext(locations);
ctx.registerShutdownHook();
contextKeyToContextMap.put(key, ctx);
}
return ctx;
}
public static void main(String... args) {
ConfigurableApplicationContext context = new SpringApplicationBuilder()
.sources(DeviceHiveAuthApplication.class)
.web(true)
.run(args);
context.registerShutdownHook();
}
public static void main(String... args) {
ConfigurableApplicationContext context = new SpringApplicationBuilder()
.sources(DeviceHiveFrontendApplication.class)
.web(true)
.run(args);
context.registerShutdownHook();
}
public static void main(String... args) {
ConfigurableApplicationContext context = new SpringApplicationBuilder()
.sources(DeviceHiveBackendApplication.class)
.web(false)
.run(args);
context.registerShutdownHook();
}
public static void main(String... args) {
ConfigurableApplicationContext context = new SpringApplicationBuilder()
.sources(DeviceHivePluginApplication.class)
.web(true)
.run(args);
context.registerShutdownHook();
}
public static void main(String[] args) {
ConfigurableApplicationContext run = SpringApplication.run(Main.class, args);
run.registerShutdownHook();
}
public static void main(String[] args) {
ConfigurableApplicationContext context = SpringApplication.run(Application.class, args);
context.registerShutdownHook();
}
@Test
public void testRegisterShutdownHook() {
ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("classpathxmlapplicationcontext-example.xml");
context.registerShutdownHook();
}