Java Code Examples for org.springframework.context.ConfigurableApplicationContext#start()
The following examples show how to use
org.springframework.context.ConfigurableApplicationContext#start() .
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: SpringMultiContextTest.java From joyrpc with Apache License 2.0 | 5 votes |
@Test public void testPlugin() { ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(SpringLoaderAutoConfiguration.class, ConsumerAutoConfiguration.class); context.setParent(parent); context.start(); ExtensionPoint<Consumer, String> consumer = new ExtensionPointLazy<Consumer, String>(Consumer.class); Assert.assertEquals(consumer.size(), 2); Consumer target = consumer.get(); Assert.assertNotNull(target); context.close(); Assert.assertEquals(consumer.size(), 1); target = consumer.get(); Assert.assertNotNull(target); }
Example 2
Source File: ApplicationListenerOnSpringEventsBootstrap.java From thinking-in-spring-boot-samples with Apache License 2.0 | 5 votes |
public static void main(String[] args) { // 创建 ConfigurableApplicationContext 实例 GenericApplicationContext ConfigurableApplicationContext context = new GenericApplicationContext(); System.out.println("创建 Spring 应用上下文 : " + context.getDisplayName()); // 添加 ApplicationListener 非泛型实现 context.addApplicationListener(event -> System.out.println(event.getClass().getSimpleName()) ); // refresh() : 初始化应用上下文 System.out.println("应用上下文准备初始化..."); context.refresh(); // 发布 ContextRefreshedEvent System.out.println("应用上下文已初始化..."); // stop() : 停止应用上下文 System.out.println("应用上下文准备停止启动..."); context.stop(); // 发布 ContextStoppedEvent System.out.println("应用上下文已停止启动..."); // start(): 启动应用上下文 System.out.println("应用上下文准备启动启动..."); context.start(); // 发布 ContextStartedEvent System.out.println("应用上下文已启动启动..."); // close() : 关闭应用上下文 System.out.println("应用上下文准备关闭..."); context.close(); // 发布 ContextClosedEvent System.out.println("应用上下文已关闭..."); }
Example 3
Source File: ContextStartAfterRefreshListener.java From spring-cloud-stream with Apache License 2.0 | 5 votes |
@Override public void onApplicationEvent(ContextRefreshedEvent event) { ConfigurableApplicationContext source = (ConfigurableApplicationContext) event .getSource(); if (source == this.applicationContext && !source.isRunning()) { source.start(); } }
Example 4
Source File: SpringRunner.java From tutorials with MIT License | 4 votes |
public static void main(String[] args) { ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(EventConfig.class); ctx.start(); }
Example 5
Source File: OnceApplicationContextEventListenerTest.java From spring-context-support with Apache License 2.0 | 3 votes |
private void testOnceApplicationContextEventListener(int levels, boolean listenersAsBean) { ConfigurableApplicationContext context = createContext(levels, listenersAsBean); context.start(); context.stop(); context.close(); }