Java Code Examples for org.springframework.context.ConfigurableApplicationContext#setId()

The following examples show how to use org.springframework.context.ConfigurableApplicationContext#setId() . 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: GeminiPostgresql.java    From gemini with Apache License 2.0 6 votes vote down vote up
public static void start(String[] args, Set<Class> coreBean, Set<Class> apiBean) {
    logger.info("***** STARTING GEMINI POSTRESQL MAIN *****");

    ConfigurableApplicationContext root = getGeminiRootContext(args, coreBean);

    logger.info("STARTING - GEMINI-WEBAPP CONTEXT ");
    SpringApplicationBuilder webAppBuilder = new SpringApplicationBuilder()
            .parent(root).sources(Api.class).sources(GuiAPI.class, AuthModuleAPI.class, AutoConfiguration.class).web(WebApplicationType.SERVLET);
    if (apiBean.size() != 0) {
        webAppBuilder.sources(apiBean.toArray(new Class[0]));
    }
    ConfigurableApplicationContext gui = webAppBuilder.bannerMode(Banner.Mode.OFF)
            .run(args);
    gui.setId("GEMINI-WAPP");
    logger.info("STARTED - GEMINI-WEBAPP CONTEXT");
}
 
Example 2
Source File: GeminiPostgresql.java    From gemini with Apache License 2.0 6 votes vote down vote up
@NotNull
private static ConfigurableApplicationContext getGeminiRootContext(String[] args, Set<Class> coreBean) {
    logger.info("STARTING - GEMINI-ROOT CONTEXT ");
    SpringApplicationBuilder appBuilder = new SpringApplicationBuilder()
            .parent(AutoConfiguration.class, Gemini.class, AuthModule.class, GuiModule.class);
    if (coreBean.size() != 0) {
        appBuilder.sources(coreBean.toArray(new Class[0]));
    }
    ConfigurableApplicationContext root = appBuilder
            .web(WebApplicationType.NONE)
            .bannerMode(Banner.Mode.OFF)
            .run(args);
    root.setId("GEMINI-ROOT");
    Gemini gemini = root.getBean(Gemini.class);
    gemini.init();
    logger.info("STARTED - GEMINI-ROOT CONTEXT");
    return root;
}
 
Example 3
Source File: GeminiPostgresql.java    From gemini with Apache License 2.0 5 votes vote down vote up
public static void startfor3Party(String[] args, Set<Class> coreBean, Set<Class> childContextBean) {
    logger.info("***** STARTING GEMINI POSTRESQL 3PARTY MAIN *****");
    ConfigurableApplicationContext root = getGeminiRootContext(args, coreBean);

    logger.info("STARTING - GEMINI-CHILD CONTEXT ");
    SpringApplicationBuilder webAppBuilder = new SpringApplicationBuilder()
            .parent(root).sources(AutoConfiguration.class).web(WebApplicationType.NONE);
    if (childContextBean.size() != 0) {
        webAppBuilder.sources(childContextBean.toArray(new Class[0]));
    }
    ConfigurableApplicationContext gui = webAppBuilder.bannerMode(Banner.Mode.OFF)
            .run(args);
    gui.setId("GEMINI-CHILD");
    logger.info("STARTED - GEMINI-CHILD CONTEXT");
}
 
Example 4
Source File: TestAppMain.java    From gemini with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {

        ConfigurableApplicationContext root = new SpringApplicationBuilder()
                .parent(Gemini.class, TestAppMain.class).web(WebApplicationType.NONE)
                .bannerMode(Banner.Mode.OFF)
                .run(args);
        root.setId("Root");

        ConfigurableApplicationContext webApp = new SpringApplicationBuilder()
                .parent(root).sources(Api.class, TestAppMain.class).web(WebApplicationType.SERVLET)
                .bannerMode(Banner.Mode.OFF)
                .run(args);
        webApp.setId("API");
    }
 
Example 5
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 6
Source File: SpringBoot13ActuatorEndpointsBootstrap.java    From thinking-in-spring-boot-samples with Apache License 2.0 4 votes vote down vote up
private static ConfigurableApplicationContext parentContext(Class... annotatedClasses) {
    // AnnotationConfigApplicationContext 构造器传递配置类,自动 refresh()
    ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(annotatedClasses);
    context.setId("parent-context"); // 设置 parent 应用上下文 Id 为 parent-context
    return context;
}