Java Code Examples for org.springframework.boot.context.event.ApplicationPreparedEvent#getApplicationContext()

The following examples show how to use org.springframework.boot.context.event.ApplicationPreparedEvent#getApplicationContext() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ApplicationPreparedEventListener.java    From thinking-in-spring-boot-samples with Apache License 2.0 5 votes vote down vote up
@Override
public void onApplicationEvent(ApplicationPreparedEvent event) {
    // 获取 Spring 应用上下文
    ConfigurableApplicationContext context = event.getApplicationContext();
    // 调整 Spring 应用上下文的 ID
    context.setId("context-mercyblitz");
    System.out.println("当前 Spring 应用上下文 ID 调整为:" + context.getId());
}
 
Example 2
Source File: PreparedEventApplicationListener.java    From micro-service with MIT License 5 votes vote down vote up
@Override
public void onApplicationEvent(ApplicationPreparedEvent event) {
	
	ConfigurableApplicationContext context = event.getApplicationContext();
	getApplicationContext(context);
	
	logger.info("3 上下文创建完成, PreparedEventApplicationListener...");
}
 
Example 3
Source File: CloudConfigApplicationListener.java    From kork with Apache License 2.0 5 votes vote down vote up
@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);
    }
  }
}
 
Example 4
Source File: ApplicationPreparedEventListener.java    From seed with Apache License 2.0 4 votes vote down vote up
@Override
public void onApplicationEvent(ApplicationPreparedEvent event) {
    ConfigurableApplicationContext cac = event.getApplicationContext();
    System.out.println("SpringBoot上下文Context创建完成,但此时Spring中的Bean是没有完全加载完成的,得到ApplicationContext-->" + cac.getDisplayName());
}