下面列出了org.springframework.boot.context.event.ApplicationPreparedEvent#getApplicationContext ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void onApplicationEvent(ApplicationPreparedEvent event) {
// 获取 Spring 应用上下文
ConfigurableApplicationContext context = event.getApplicationContext();
// 调整 Spring 应用上下文的 ID
context.setId("context-mercyblitz");
System.out.println("当前 Spring 应用上下文 ID 调整为:" + context.getId());
}
@Override
public void onApplicationEvent(ApplicationPreparedEvent event) {
ConfigurableApplicationContext context = event.getApplicationContext();
getApplicationContext(context);
logger.info("3 上下文创建完成, PreparedEventApplicationListener...");
}
@Override
public void onApplicationEvent(ApplicationPreparedEvent event) {
ConfigurableApplicationContext context = event.getApplicationContext();
ConfigurableEnvironment environment = context.getEnvironment();
for (PropertySource propertySource : environment.getPropertySources()) {
if (shouldWrap(propertySource)) {
CloudConfigAwarePropertySource wrapper =
new CloudConfigAwarePropertySource(propertySource, context);
environment.getPropertySources().replace(propertySource.getName(), wrapper);
}
}
}
@Override
public void onApplicationEvent(ApplicationPreparedEvent event) {
ConfigurableApplicationContext cac = event.getApplicationContext();
System.out.println("SpringBoot上下文Context创建完成,但此时Spring中的Bean是没有完全加载完成的,得到ApplicationContext-->" + cac.getDisplayName());
}