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

The following examples show how to use org.springframework.context.ConfigurableApplicationContext#registerShutdownHook() . 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
Source File: SpringApplication.java    From spring-javaformat with Apache License 2.0 5 votes vote down vote up
private void refreshContext(ConfigurableApplicationContext context) {
	refresh(context);
	if (this.registerShutdownHook) {
		try {
			context.registerShutdownHook();
		}
		catch (AccessControlException ex) {
			// Not allowed in some environments.
		}
	}
}
 
Example 2
Source File: TestRefreshableApplicationContextLoader.java    From spring-boot-data-geode with Apache License 2.0 5 votes vote down vote up
/**
 * @inheritDoc
 */
@Override
public ApplicationContext loadContext(MergedContextConfiguration mergedConfig) {

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

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

	return applicationContext;
}
 
Example 3
Source File: AbstractSpringContextTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * 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
Source File: DeviceHiveAuthApplication.java    From devicehive-java-server with Apache License 2.0 5 votes vote down vote up
public static void main(String... args) {
    ConfigurableApplicationContext context = new SpringApplicationBuilder()
            .sources(DeviceHiveAuthApplication.class)
            .web(true)
            .run(args);

    context.registerShutdownHook();
}
 
Example 5
Source File: DeviceHiveFrontendApplication.java    From devicehive-java-server with Apache License 2.0 5 votes vote down vote up
public static void main(String... args) {
    ConfigurableApplicationContext context = new SpringApplicationBuilder()
            .sources(DeviceHiveFrontendApplication.class)
            .web(true)
            .run(args);

    context.registerShutdownHook();
}
 
Example 6
Source File: DeviceHiveBackendApplication.java    From devicehive-java-server with Apache License 2.0 5 votes vote down vote up
public static void main(String... args) {
    ConfigurableApplicationContext context = new SpringApplicationBuilder()
            .sources(DeviceHiveBackendApplication.class)
            .web(false)
            .run(args);

    context.registerShutdownHook();
}
 
Example 7
Source File: DeviceHivePluginApplication.java    From devicehive-java-server with Apache License 2.0 5 votes vote down vote up
public static void main(String... args) {
    ConfigurableApplicationContext context = new SpringApplicationBuilder()
            .sources(DeviceHivePluginApplication.class)
            .web(true)
            .run(args);

    context.registerShutdownHook();
}
 
Example 8
Source File: Main.java    From java-11-examples with 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 File: Application.java    From NFVO with 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
Source File: ClasspathXmlApplicationContextIntegrationTest.java    From tutorials with MIT License 4 votes vote down vote up
@Test
public void testRegisterShutdownHook() {
    ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("classpathxmlapplicationcontext-example.xml");
    context.registerShutdownHook();
}