本文整理汇总了Java中org.springframework.context.ConfigurableApplicationContext.publishEvent方法的典型用法代码示例。如果您正苦于以下问题:Java ConfigurableApplicationContext.publishEvent方法的具体用法?Java ConfigurableApplicationContext.publishEvent怎么用?Java ConfigurableApplicationContext.publishEvent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.context.ConfigurableApplicationContext
的用法示例。
在下文中一共展示了ConfigurableApplicationContext.publishEvent方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.springframework.context.ConfigurableApplicationContext; //导入方法依赖的package包/类
public static void main(String[] args) {
SpringApplication bootstrap = new SpringApplication(SpringBootRunner.class);
bootstrap.addListeners(new MyStartListner());
// 对Context进行最后的设置工作
bootstrap.addInitializers(new MyContextInitializer());
// 增加命令
ConfigurableApplicationContext context = bootstrap.run(args);
// 触发一个事件
MyTellEvent event = new MyTellEvent(context, "测试的事件信息");
context.publishEvent(event);
}
示例2: publishDiscoveryEvent
import org.springframework.context.ConfigurableApplicationContext; //导入方法依赖的package包/类
private void publishDiscoveryEvent()
{
if (this.config == null)
{
return;
}
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);
}
}
});
}
}