Java Code Examples for org.springframework.context.ConfigurableApplicationContext#registerShutdownHook()

The following examples show how to use org.springframework.context.ConfigurableApplicationContext#registerShutdownHook() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
private void refreshContext(ConfigurableApplicationContext context) {
	refresh(context);
	if (this.registerShutdownHook) {
		try {
			context.registerShutdownHook();
		}
		catch (AccessControlException ex) {
			// Not allowed in some environments.
		}
	}
}
 
Example 2
/**
 * @inheritDoc
 */
@Override
public ApplicationContext loadContext(MergedContextConfiguration mergedConfig) {

	ConfigurableApplicationContext applicationContext =
		configure(newApplicationContext(mergedConfig), mergedConfig);

	applicationContext.registerShutdownHook();
	applicationContext.refresh();

	return applicationContext;
}
 
Example 3
/**
 * 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;
}
 
Example 4
public static void main(String... args) {
    ConfigurableApplicationContext context = new SpringApplicationBuilder()
            .sources(DeviceHiveAuthApplication.class)
            .web(true)
            .run(args);

    context.registerShutdownHook();
}
 
Example 5
public static void main(String... args) {
    ConfigurableApplicationContext context = new SpringApplicationBuilder()
            .sources(DeviceHiveFrontendApplication.class)
            .web(true)
            .run(args);

    context.registerShutdownHook();
}
 
Example 6
public static void main(String... args) {
    ConfigurableApplicationContext context = new SpringApplicationBuilder()
            .sources(DeviceHiveBackendApplication.class)
            .web(false)
            .run(args);

    context.registerShutdownHook();
}
 
Example 7
public static void main(String... args) {
    ConfigurableApplicationContext context = new SpringApplicationBuilder()
            .sources(DeviceHivePluginApplication.class)
            .web(true)
            .run(args);

    context.registerShutdownHook();
}
 
Example 8
Source Project: java-11-examples   File: Main.java    License: Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
    ConfigurableApplicationContext run = SpringApplication.run(Main.class, args);
    run.registerShutdownHook();
}
 
Example 9
Source Project: NFVO   File: Application.java    License: Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {

    ConfigurableApplicationContext context = SpringApplication.run(Application.class, args);
    context.registerShutdownHook();
  }
 
Example 10
@Test
public void testRegisterShutdownHook() {
    ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("classpathxmlapplicationcontext-example.xml");
    context.registerShutdownHook();
}