本文整理汇总了Java中org.springframework.context.event.ApplicationContextEvent类的典型用法代码示例。如果您正苦于以下问题:Java ApplicationContextEvent类的具体用法?Java ApplicationContextEvent怎么用?Java ApplicationContextEvent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ApplicationContextEvent类属于org.springframework.context.event包,在下文中一共展示了ApplicationContextEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onApplicationEvent
import org.springframework.context.event.ApplicationContextEvent; //导入依赖的package包/类
@Override
public void onApplicationEvent(ApplicationContextEvent event) {
if (event instanceof ContextRefreshedEvent && !servicePublisherStarted) {
// Application initialization complete. Export astrix-services.
if (isServer()) {
this.astrixContext.startServicePublisher();
}
servicePublisherStarted = true;
} else if (event instanceof ContextClosedEvent || event instanceof ContextStoppedEvent) {
/*
* What's the difference between the "stopped" and "closed" event? In our embedded
* integration tests we only receive ContextClosedEvent
*/
destroyAstrixContext();
}
}
示例2: onApplicationEvent
import org.springframework.context.event.ApplicationContextEvent; //导入依赖的package包/类
@Override
public void onApplicationEvent(ApplicationContextEvent event) {
try {
if (event instanceof ContextRefreshedEvent && !isDeployed) {
// deploy the process application
afterPropertiesSet();
} else if (event instanceof ContextClosedEvent) {
// undeploy the process application
destroy();
} else {
// ignore
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例3: onApplicationEvent
import org.springframework.context.event.ApplicationContextEvent; //导入依赖的package包/类
@Override
public void onApplicationEvent(ApplicationContextEvent event) {
if (event instanceof ContextClosedEvent || event instanceof ContextStoppedEvent) {
List<Entity> everyone = entityRepository.findByXIsNotNullAndYIsNotNullAndZIsNotNull();
GameOutput output = new GameOutput("[red]EmergentMUD is shutting down. Please check back later!");
entityService.sendMessageToListeners(everyone, output);
}
}
示例4: onApplicationEvent
import org.springframework.context.event.ApplicationContextEvent; //导入依赖的package包/类
public void onApplicationEvent(ApplicationContextEvent event) {
// publish
if (event instanceof ContextRefreshedEvent) {
registerService(event.getApplicationContext());
} else if (event instanceof ContextClosedEvent) {
unregisterService();
}
}
示例5: onApplicationEvent
import org.springframework.context.event.ApplicationContextEvent; //导入依赖的package包/类
@Override
public final void onApplicationEvent(final ApplicationContextEvent event) {
try {
final ApplicationContext context = event.getApplicationContext();
if (context instanceof XmlWebApplicationContext) {
final XmlWebApplicationContext ctx = (XmlWebApplicationContext) context;
String webContextName = ctx.getServletContext().getServletContextName();
if (webContextName.contains("/")) {
webContextName = webContextName.substring(webContextName.indexOf('/'));
}
ctx.setDisplayName(webContextName);
MDC.put(LeveringVeld.MDC_APPLICATIE_NAAM, webContextName).close();
}
LOGGER.debug("Context event '{}'; id='{}', displayName='{}'", event.getClass().getSimpleName(), event
.getApplicationContext().getId(), event.getApplicationContext().getDisplayName());
if (event instanceof ContextClosedEvent) {
LOGGER.info("==> Context voor applicatie '{}' is gestopt", event.getApplicationContext().getId());
}
/* Wanneer een applicatie is gestart, dan wordt een ContextRefreshedEvent gestuurt **/
if (event instanceof ContextRefreshedEvent) {
LOGGER.info("==> Context voor applicatie '{}' is gestart/herstart", event.getApplicationContext()
.getId());
logJvmSettings();
}
} catch (final ApplicationContextException ex) {
LOGGER.error("Fout bij het opstarten van de applicatiecontext bij event {}", event.toString(), ex);
}
}
示例6: contextRefreshed
import org.springframework.context.event.ApplicationContextEvent; //导入依赖的package包/类
@Test
public void contextRefreshed() throws Exception {
Assert.assertEquals(2, contextRefreshedList.size());
for (int i = 0; i < contextRefreshedList.size(); i++)
Assert.assertEquals(i + 1, numeric.toInt(contextRefreshedList.get(i)));
for (int i = 0; i < 2; i++) {
((ContainerImpl) container).onApplicationEvent(new ContextRefreshedEvent(getApplicationContext()));
Assert.assertEquals(4 + i * 2, contextRefreshedList.size());
for (int j = 0; j < contextRefreshedList.size(); j++)
Assert.assertEquals(j % 2 + 1, numeric.toInt(contextRefreshedList.get(j)));
}
Field field = ContainerImpl.class.getDeclaredField("refreshedListeners");
field.setAccessible(true);
Object object = field.get(container);
field.set(container, Optional.empty());
for (int i = 0; i < 2; i++) {
((ContainerImpl) container).onApplicationEvent(new ContextRefreshedEvent(getApplicationContext()));
Assert.assertEquals(6, contextRefreshedList.size());
for (int j = 0; j < contextRefreshedList.size(); j++)
Assert.assertEquals(j % 2 + 1, numeric.toInt(contextRefreshedList.get(j)));
}
((ContainerImpl) container).onApplicationEvent(new ApplicationContextEvent(getApplicationContext()) {
});
Assert.assertEquals(6, contextRefreshedList.size());
for (int i = 0; i < contextRefreshedList.size(); i++)
Assert.assertEquals(i % 2 + 1, numeric.toInt(contextRefreshedList.get(i)));
field.set(container, object);
}
示例7: contextClosed
import org.springframework.context.event.ApplicationContextEvent; //导入依赖的package包/类
@Test
public void contextClosed() throws Exception {
for (int i = 0; i < 2; i++) {
((ContainerImpl) container).onApplicationEvent(new ContextClosedEvent(getApplicationContext()));
Assert.assertEquals(2 + i * 2, contextClosedList.size());
for (int j = 0; j < contextRefreshedList.size(); j++)
Assert.assertEquals(j % 2 + 1, numeric.toInt(contextClosedList.get(j)));
}
Field field = ContainerImpl.class.getDeclaredField("closedListeners");
field.setAccessible(true);
Object object = field.get(container);
field.set(container, Optional.empty());
for (int i = 0; i < 2; i++) {
((ContainerImpl) container).onApplicationEvent(new ContextClosedEvent(getApplicationContext()));
Assert.assertEquals(4, contextClosedList.size());
for (int j = 0; j < contextClosedList.size(); j++)
Assert.assertEquals(j % 2 + 1, numeric.toInt(contextClosedList.get(j)));
}
((ContainerImpl) container).onApplicationEvent(new ApplicationContextEvent(getApplicationContext()) {
});
Assert.assertEquals(4, contextClosedList.size());
for (int i = 0; i < contextClosedList.size(); i++)
Assert.assertEquals(i % 2 + 1, numeric.toInt(contextClosedList.get(i)));
field.set(container, object);
}
示例8: onApplicationEvent
import org.springframework.context.event.ApplicationContextEvent; //导入依赖的package包/类
protected void onApplicationEvent(ApplicationEvent event) {
ConfigurableApplicationContext initializerApplicationContext = AutoConfigurationReportLoggingInitializer.this.applicationContext;
if (event instanceof ContextRefreshedEvent) {
if (((ApplicationContextEvent) event)
.getApplicationContext() == initializerApplicationContext) {
logAutoConfigurationReport();
}
}
else if (event instanceof ApplicationFailedEvent) {
if (((ApplicationFailedEvent) event)
.getApplicationContext() == initializerApplicationContext) {
logAutoConfigurationReport(true);
}
}
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:16,代码来源:AutoConfigurationReportLoggingInitializer.java
示例9: onApplicationEvent
import org.springframework.context.event.ApplicationContextEvent; //导入依赖的package包/类
/**
* {@inheritDoc}
* @see org.springframework.context.ApplicationListener#onApplicationEvent(org.springframework.context.ApplicationEvent)
*/
@Override
public void onApplicationEvent(final ApplicationContextEvent event) {
if(event.getApplicationContext()==appCtx) {
if(event instanceof ContextRefreshedEvent) {
start();
} else if(event instanceof ContextStoppedEvent) {
stop();
}
}
}
示例10: onApplicationEvent
import org.springframework.context.event.ApplicationContextEvent; //导入依赖的package包/类
/**
* {@inheritDoc}
* @see org.springframework.context.ApplicationListener#onApplicationEvent(org.springframework.context.ApplicationEvent)
*/
@Override
public void onApplicationEvent(final ApplicationContextEvent event) {
if(event.getApplicationContext()==appCtx) {
if(event instanceof ContextRefreshedEvent) {
try {
start();
} catch (Exception ex) {
throw new RuntimeException(ex);
}
} else if(event instanceof ContextClosedEvent) {
stop();
}
}
}
示例11: onApplicationEvent
import org.springframework.context.event.ApplicationContextEvent; //导入依赖的package包/类
@Override
public void onApplicationEvent(ApplicationContextEvent event) {
if (event instanceof ContextRefreshedEvent && event.getApplicationContext().getParent() == null) {
startMuleContext(event.getApplicationContext());
} else if (event instanceof ContextClosedEvent) {
stopMuleContext();
}
}
示例12: onApplicationEvent
import org.springframework.context.event.ApplicationContextEvent; //导入依赖的package包/类
public void onApplicationEvent(ApplicationEvent event) {
if (event instanceof ContextRefreshedEvent || event instanceof ContextBeanChangedEvent) {
ApplicationContext context = ((ApplicationContextEvent) event).getApplicationContext();
boolean hasInboundChannels = !context.getBeansOfType(InboundChannel.class).isEmpty();
int flowControls = context.getBeansOfType(PipelineFlowControl.class).size();
// Ignore this, but if there are others, register for management
if (hasInboundChannels || flowControls > 1) {
Management.removeBeanOrFolder(getBeanName(), this);
Management.addBean(getBeanName(), this);
}
}
}
示例13: onApplicationEvent
import org.springframework.context.event.ApplicationContextEvent; //导入依赖的package包/类
@Override
public void onApplicationEvent(ApplicationContextEvent arg0) {
if (arg0 instanceof ContextRefreshedEvent) {
LOG.warn("READY: " + this.version);
} else if (arg0 instanceof ContextClosedEvent) {
LOG.warn("SHUTDOWN: " + this.version);
}
}
示例14: onApplicationEvent
import org.springframework.context.event.ApplicationContextEvent; //导入依赖的package包/类
@Override
public void onApplicationEvent(ApplicationContextEvent event) {
ApplicationContext ctx = event.getApplicationContext();
if(!(ctx instanceof AnnotationConfigWebApplicationContext))
throw new RuntimeException("Initialization of the apllication-context failed!");
try {
FileSystemUtil fsu = ctx.getBean(FileSystemUtil.class);
fsu.init();
} catch (Exception e) {
throw new RuntimeException(e);
}
logger.info("*** Application-context successful initialized");
}
示例15: onApplicationEvent
import org.springframework.context.event.ApplicationContextEvent; //导入依赖的package包/类
/**
* Listens for application lifecycle events (specifically start/stop),
* and schedules the new run/cancels the next run as appropriate.
*
* @param event the application event to process.
*/
@Override
public void onApplicationEvent(final ApplicationContextEvent event) {
if (event instanceof ContextRefreshedEvent) {
this.applicationContext = event.getApplicationContext();
this.startTimer();
} else if (event instanceof ContextClosedEvent) {
this.cancel();
this.applicationContext = null;
// This manually deregisters JDBC driver, which prevents Tomcat 7
// from complaining about memory leaks from this class
// XXX: Disabled as it's dangerous and Tomcat handles this much
// better, even if it does complain
/* Enumeration<Driver> drivers = DriverManager.getDrivers();
while (drivers.hasMoreElements()) {
final Driver driver = drivers.nextElement();
// Really ought to take the list of drivers to de-register from
// application context
if (driver instanceof com.microsoft.sqlserver.jdbc.SQLServerDriver) {
try {
DriverManager.deregisterDriver(driver);
} catch (SQLException e) {
log.error(String.format("Error deregistering driver %s", driver), e);
}
}
} */
}
}