@Override public void onApplicationEvent(ContextStartedEvent event) { ApplicationContext applicationContext = event.getApplicationContext(); /** init search service **/ SearchService searchService = (SearchService)applicationContext.getBean("productSearchService"); searchService.initService(); }
@Override public void start() { getLifecycleProcessor().start(); publishEvent(new ContextStartedEvent(this)); }
@Override public void onApplicationEvent(ApplicationEvent event) { if (event instanceof ContextStartedEvent) { this.context = ((ContextStartedEvent) event).getApplicationContext(); this.startedCount++; } else if (event instanceof ContextStoppedEvent) { this.context = ((ContextStoppedEvent) event).getApplicationContext(); this.stoppedCount++; } }
@Override public void start() { getLifecycleProcessor().start(); publishEvent(new ContextStartedEvent(this)); }
public class Loader implements ApplicationListener<ContextStartedEvent> { public void onApplicationEvent(ContextStartedEvent event) { ApplicationContext context = event.getApplicationContext(); } }
@Override public void start() { getLifecycleProcessor().start(); publishEvent(new ContextStartedEvent(this)); }
@EventListener public void handleContextRefresh(ContextStartedEvent event) { setApplicationContext(event.getApplicationContext()); }
@Override public void onApplicationEvent(Object event) { if (event instanceof StartupEvent) { eventPublisher.publishEvent(new ContextStartedEvent( applicationContext )); } else if (event instanceof ShutdownEvent) { eventPublisher.publishEvent(new ContextClosedEvent( applicationContext )); } } }
ContextStartedEvent event = ...; // from method argument ConfigurableEnvironment env = (ConfigurableEnvironment) event.getApplicationContext().getEnvironment(); env.setActiveProfiles("master");
@EventListener private void contextStarted(ContextStartedEvent event) { ApplicationContext context = event.getApplicationContext(); if (log.isInfoEnabled()) { log.info("Spring context '" + context.getId() +"' started: " + context.getDisplayName()); } }