List of usage examples for org.springframework.context ConfigurableApplicationContext addApplicationListener
void addApplicationListener(ApplicationListener<?> listener);
From source file:com.javiermoreno.springboot.mvc.minimal.httpd.App.java
public static void main(String[] args) { ConfigurableApplicationContext context = new SpringApplicationBuilder().showBanner(true).sources(App.class) .run(args);/*from w w w . j a v a 2s.co m*/ context.addApplicationListener(new ApplicationPidListener()); }
From source file:com.javiermoreno.springboot.rest.App.java
public static void main(String[] args) { ConfigurableApplicationContext context = new SpringApplicationBuilder().showBanner(true).sources(App.class) .run(args);/*from ww w .j a v a2 s . co m*/ context.addApplicationListener(new ApplicationPidListener()); GestionPersonasService service = context.getBean(GestionPersonasService.class); service.registrarNuevaPersona(new Persona("11111111A", "Karl", "Marx")); }
From source file:com.linecorp.bot.spring.boot.support.LineMessageHandlerSupport.java
@Autowired public LineMessageHandlerSupport(final ReplyByReturnValueConsumer.Factory returnValueConsumerFactory, final ConfigurableApplicationContext applicationContext) { this.returnValueConsumerFactory = returnValueConsumerFactory; this.applicationContext = applicationContext; applicationContext.addApplicationListener(event -> { if (event instanceof ContextRefreshedEvent) { refresh();/*from ww w . j ava2 s. com*/ } }); }
From source file:org.alfresco.repo.search.impl.lucene.index.IndexInfo.java
private void publishDiscoveryEvent() { if (this.config == null) { return;/*w w w. j a v a2 s .c o m*/ } final IndexEvent discoveryEvent = new IndexEvent(this, "Discovery", 1); final ConfigurableApplicationContext applicationContext = this.config.getApplicationContext(); try { applicationContext.publishEvent(discoveryEvent); } catch (IllegalStateException e) { // There's a possibility that the application context hasn't fully refreshed yet, so register a listener // that will fire when it has applicationContext.addApplicationListener(new ApplicationListener() { public void onApplicationEvent(ApplicationEvent event) { if (event instanceof ContextRefreshedEvent) { applicationContext.publishEvent(discoveryEvent); } } }); } }
From source file:org.cloudfoundry.identity.uaa.mock.util.MockMvcUtils.java
public static <T extends ApplicationEvent> TestApplicationEventListener<T> addEventListener( ConfigurableApplicationContext applicationContext, Class<T> clazz) { TestApplicationEventListener<T> listener = TestApplicationEventListener.forEventClass(clazz); applicationContext.addApplicationListener(listener); return listener; }
From source file:org.dspace.app.rest.utils.DSpaceKernelInitializer.java
@Override public void initialize(final ConfigurableApplicationContext applicationContext) { // Check if the kernel is already started this.dspaceKernel = DSpaceKernelManager.getDefaultKernel(); if (this.dspaceKernel == null) { DSpaceKernelImpl kernelImpl = null; try {//from ww w. ja va 2 s .c om // Load the kernel with default settings kernelImpl = DSpaceKernelInit.getKernel(null); if (!kernelImpl.isRunning()) { // Determine configured DSpace home & init the Kernel kernelImpl.start(getDSpaceHome(applicationContext.getEnvironment())); } this.dspaceKernel = kernelImpl; } catch (Exception e) { // failed to start so destroy it and log and throw an exception try { if (kernelImpl != null) { kernelImpl.destroy(); } this.dspaceKernel = null; } catch (Exception e1) { // nothing } String message = "Failure during ServletContext initialisation: " + e.getMessage(); log.error(message, e); throw new RuntimeException(message, e); } } if (applicationContext.getParent() == null) { // Set the DSpace Kernel Application context as a parent of the Spring Boot context so that // we can auto-wire all DSpace Kernel services applicationContext.setParent(dspaceKernel.getServiceManager().getApplicationContext()); //Add a listener for Spring Boot application shutdown so that we can nicely cleanup the DSpace kernel. applicationContext.addApplicationListener(new DSpaceKernelDestroyer(dspaceKernel)); } }
From source file:org.kuali.rice.krad.datadictionary.ReloadingDataDictionary.java
@Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { // register a context close handler if (applicationContext instanceof ConfigurableApplicationContext) { ConfigurableApplicationContext context = (ConfigurableApplicationContext) applicationContext; context.addApplicationListener(new ApplicationListener<ContextClosedEvent>() { @Override/*from www.j av a2 s. c om*/ public void onApplicationEvent(ContextClosedEvent e) { LOG.info("Context '" + e.getApplicationContext().getDisplayName() + "' closed, shutting down URLMonitor scheduler"); dictionaryUrlMonitor.shutdownScheduler(); } }); } }
From source file:org.springframework.boot.autoconfigure.logging.AutoConfigurationReportLoggingInitializer.java
@Override public void initialize(ConfigurableApplicationContext applicationContext) { this.applicationContext = applicationContext; applicationContext.addApplicationListener(new AutoConfigurationReportListener()); if (applicationContext instanceof GenericApplicationContext) { // Get the report early in case the context fails to load this.report = ConditionEvaluationReport.get(this.applicationContext.getBeanFactory()); }//from ww w.j a va 2 s . co m }
From source file:org.springframework.boot.autoconfigure.logging.ConditionEvaluationReportLoggingListener.java
@Override public void initialize(ConfigurableApplicationContext applicationContext) { this.applicationContext = applicationContext; applicationContext.addApplicationListener(new ConditionEvaluationReportListener()); if (applicationContext instanceof GenericApplicationContext) { // Get the report early in case the context fails to load this.report = ConditionEvaluationReport.get(this.applicationContext.getBeanFactory()); }//from w ww.ja v a 2 s . c o m }