Java 类org.springframework.boot.context.event.ApplicationPreparedEvent 实例源码

项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:LoggingApplicationListener.java   
@Override
public void onApplicationEvent(ApplicationEvent event) {
    if (event instanceof ApplicationStartedEvent) {
        onApplicationStartedEvent((ApplicationStartedEvent) event);
    }
    else if (event instanceof ApplicationEnvironmentPreparedEvent) {
        onApplicationEnvironmentPreparedEvent(
                (ApplicationEnvironmentPreparedEvent) event);
    }
    else if (event instanceof ApplicationPreparedEvent) {
        onApplicationPreparedEvent((ApplicationPreparedEvent) event);
    }
    else if (event instanceof ContextClosedEvent && ((ContextClosedEvent) event)
            .getApplicationContext().getParent() == null) {
        onContextClosedEvent();
    }
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:SpringApplicationTests.java   
@Test
public void eventsOrder() {
    SpringApplication application = new SpringApplication(ExampleConfig.class);
    application.setWebEnvironment(false);
    final List<ApplicationEvent> events = new ArrayList<ApplicationEvent>();
    class ApplicationRunningEventListener
            implements ApplicationListener<ApplicationEvent> {
        @Override
        public void onApplicationEvent(ApplicationEvent event) {
            events.add((event));
        }
    }
    application.addListeners(new ApplicationRunningEventListener());
    this.context = application.run();
    assertThat(events).hasSize(5);
    assertThat(events.get(0)).isInstanceOf(ApplicationStartedEvent.class);
    assertThat(events.get(1)).isInstanceOf(ApplicationEnvironmentPreparedEvent.class);
    assertThat(events.get(2)).isInstanceOf(ApplicationPreparedEvent.class);
    assertThat(events.get(3)).isInstanceOf(ContextRefreshedEvent.class);
    assertThat(events.get(4)).isInstanceOf(ApplicationReadyEvent.class);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:SpringApplicationTests.java   
@Test
public void registerListener() throws Exception {
    SpringApplication application = new SpringApplication(ExampleConfig.class,
            ListenerConfig.class);
    application.setApplicationContextClass(SpyApplicationContext.class);
    final LinkedHashSet<ApplicationEvent> events = new LinkedHashSet<ApplicationEvent>();
    application.addListeners(new ApplicationListener<ApplicationEvent>() {

        @Override
        public void onApplicationEvent(ApplicationEvent event) {
            events.add(event);
        }

    });
    this.context = application.run();
    assertThat(events).hasAtLeastOneElementOfType(ApplicationPreparedEvent.class);
    assertThat(events).hasAtLeastOneElementOfType(ContextRefreshedEvent.class);
    verifyTestListenerEvents();
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:SpringApplicationTests.java   
@Test
public void registerListenerWithCustomMulticaster() throws Exception {
    SpringApplication application = new SpringApplication(ExampleConfig.class,
            ListenerConfig.class, Multicaster.class);
    application.setApplicationContextClass(SpyApplicationContext.class);
    final LinkedHashSet<ApplicationEvent> events = new LinkedHashSet<ApplicationEvent>();
    application.addListeners(new ApplicationListener<ApplicationEvent>() {

        @Override
        public void onApplicationEvent(ApplicationEvent event) {
            events.add(event);
        }

    });
    this.context = application.run();
    assertThat(events).hasAtLeastOneElementOfType(ApplicationPreparedEvent.class);
    assertThat(events).hasAtLeastOneElementOfType(ContextRefreshedEvent.class);
    verifyTestListenerEvents();
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:RestartApplicationListener.java   
@Override
public void onApplicationEvent(ApplicationEvent event) {
    if (event instanceof ApplicationStartedEvent) {
        onApplicationStartedEvent((ApplicationStartedEvent) event);
    }
    if (event instanceof ApplicationPreparedEvent) {
        Restarter.getInstance()
                .prepare(((ApplicationPreparedEvent) event).getApplicationContext());
    }
    if (event instanceof ApplicationReadyEvent
            || event instanceof ApplicationFailedEvent) {
        Restarter.getInstance().finish();
        if (event instanceof ApplicationFailedEvent) {
            Restarter.getInstance().prepare(null);
        }
    }
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:RestartApplicationListenerTests.java   
private void testInitialize(boolean failed) {
    Restarter.clearInstance();
    RestartApplicationListener listener = new RestartApplicationListener();
    SpringApplication application = new SpringApplication();
    ConfigurableApplicationContext context = mock(
            ConfigurableApplicationContext.class);
    listener.onApplicationEvent(new ApplicationStartedEvent(application, ARGS));
    assertThat(Restarter.getInstance()).isNotEqualTo(nullValue());
    assertThat(Restarter.getInstance().isFinished()).isFalse();
    listener.onApplicationEvent(
            new ApplicationPreparedEvent(application, ARGS, context));
    if (failed) {
        listener.onApplicationEvent(new ApplicationFailedEvent(application, ARGS,
                context, new RuntimeException()));
    }
    else {
        listener.onApplicationEvent(
                new ApplicationReadyEvent(application, ARGS, context));
    }
}
项目:spring-boot-concourse    文件:LoggingApplicationListener.java   
@Override
public void onApplicationEvent(ApplicationEvent event) {
    if (event instanceof ApplicationStartedEvent) {
        onApplicationStartedEvent((ApplicationStartedEvent) event);
    }
    else if (event instanceof ApplicationEnvironmentPreparedEvent) {
        onApplicationEnvironmentPreparedEvent(
                (ApplicationEnvironmentPreparedEvent) event);
    }
    else if (event instanceof ApplicationPreparedEvent) {
        onApplicationPreparedEvent((ApplicationPreparedEvent) event);
    }
    else if (event instanceof ContextClosedEvent && ((ContextClosedEvent) event)
            .getApplicationContext().getParent() == null) {
        onContextClosedEvent();
    }
}
项目:spring-boot-concourse    文件:SpringApplicationTests.java   
@Test
public void eventsOrder() {
    SpringApplication application = new SpringApplication(ExampleConfig.class);
    application.setWebEnvironment(false);
    final List<ApplicationEvent> events = new ArrayList<ApplicationEvent>();
    class ApplicationRunningEventListener
            implements ApplicationListener<ApplicationEvent> {
        @Override
        public void onApplicationEvent(ApplicationEvent event) {
            events.add((event));
        }
    }
    application.addListeners(new ApplicationRunningEventListener());
    this.context = application.run();
    assertThat(events).hasSize(5);
    assertThat(events.get(0)).isInstanceOf(ApplicationStartedEvent.class);
    assertThat(events.get(1)).isInstanceOf(ApplicationEnvironmentPreparedEvent.class);
    assertThat(events.get(2)).isInstanceOf(ApplicationPreparedEvent.class);
    assertThat(events.get(3)).isInstanceOf(ContextRefreshedEvent.class);
    assertThat(events.get(4)).isInstanceOf(ApplicationReadyEvent.class);
}
项目:spring-boot-concourse    文件:SpringApplicationTests.java   
@Test
public void registerListener() throws Exception {
    SpringApplication application = new SpringApplication(ExampleConfig.class,
            ListenerConfig.class);
    application.setApplicationContextClass(SpyApplicationContext.class);
    final LinkedHashSet<ApplicationEvent> events = new LinkedHashSet<ApplicationEvent>();
    application.addListeners(new ApplicationListener<ApplicationEvent>() {

        @Override
        public void onApplicationEvent(ApplicationEvent event) {
            events.add(event);
        }

    });
    this.context = application.run();
    assertThat(events).hasAtLeastOneElementOfType(ApplicationPreparedEvent.class);
    assertThat(events).hasAtLeastOneElementOfType(ContextRefreshedEvent.class);
    verifyTestListenerEvents();
}
项目:spring-boot-concourse    文件:SpringApplicationTests.java   
@Test
public void registerListenerWithCustomMulticaster() throws Exception {
    SpringApplication application = new SpringApplication(ExampleConfig.class,
            ListenerConfig.class, Multicaster.class);
    application.setApplicationContextClass(SpyApplicationContext.class);
    final LinkedHashSet<ApplicationEvent> events = new LinkedHashSet<ApplicationEvent>();
    application.addListeners(new ApplicationListener<ApplicationEvent>() {

        @Override
        public void onApplicationEvent(ApplicationEvent event) {
            events.add(event);
        }

    });
    this.context = application.run();
    assertThat(events).hasAtLeastOneElementOfType(ApplicationPreparedEvent.class);
    assertThat(events).hasAtLeastOneElementOfType(ContextRefreshedEvent.class);
    verifyTestListenerEvents();
}
项目:spring-boot-concourse    文件:RestartApplicationListener.java   
@Override
public void onApplicationEvent(ApplicationEvent event) {
    if (event instanceof ApplicationStartedEvent) {
        onApplicationStartedEvent((ApplicationStartedEvent) event);
    }
    if (event instanceof ApplicationPreparedEvent) {
        Restarter.getInstance()
                .prepare(((ApplicationPreparedEvent) event).getApplicationContext());
    }
    if (event instanceof ApplicationReadyEvent
            || event instanceof ApplicationFailedEvent) {
        Restarter.getInstance().finish();
        if (event instanceof ApplicationFailedEvent) {
            Restarter.getInstance().prepare(null);
        }
    }
}
项目:spring-boot-concourse    文件:RestartApplicationListenerTests.java   
private void testInitialize(boolean failed) {
    Restarter.clearInstance();
    RestartApplicationListener listener = new RestartApplicationListener();
    SpringApplication application = new SpringApplication();
    ConfigurableApplicationContext context = mock(
            ConfigurableApplicationContext.class);
    listener.onApplicationEvent(new ApplicationStartedEvent(application, ARGS));
    assertThat(Restarter.getInstance()).isNotEqualTo(nullValue());
    assertThat(Restarter.getInstance().isFinished()).isFalse();
    listener.onApplicationEvent(
            new ApplicationPreparedEvent(application, ARGS, context));
    if (failed) {
        listener.onApplicationEvent(new ApplicationFailedEvent(application, ARGS,
                context, new RuntimeException()));
    }
    else {
        listener.onApplicationEvent(
                new ApplicationReadyEvent(application, ARGS, context));
    }
}
项目:contestparser    文件:SpringApplicationTests.java   
@Test
public void eventsOrder() {
    SpringApplication application = new SpringApplication(ExampleConfig.class);
    application.setWebEnvironment(false);
    final List<ApplicationEvent> events = new ArrayList<ApplicationEvent>();
    class ApplicationRunningEventListener
            implements ApplicationListener<ApplicationEvent> {
        @Override
        public void onApplicationEvent(ApplicationEvent event) {
            events.add((event));
        }
    }
    application.addListeners(new ApplicationRunningEventListener());
    this.context = application.run();
    assertThat(5, is(events.size()));
    assertThat(events.get(0), is(instanceOf(ApplicationStartedEvent.class)));
    assertThat(events.get(1),
            is(instanceOf(ApplicationEnvironmentPreparedEvent.class)));
    assertThat(events.get(2), is(instanceOf(ApplicationPreparedEvent.class)));
    assertThat(events.get(3), is(instanceOf(ContextRefreshedEvent.class)));
    assertThat(events.get(4), is(instanceOf(ApplicationReadyEvent.class)));
}
项目:contestparser    文件:SpringApplicationTests.java   
@Test
public void registerListenerWithCustomMulticaster() throws Exception {
    SpringApplication application = new SpringApplication(ExampleConfig.class,
            Multicaster.class);
    application.setApplicationContextClass(SpyApplicationContext.class);
    final LinkedHashSet<ApplicationEvent> events = new LinkedHashSet<ApplicationEvent>();
    application.addListeners(new ApplicationListener<ApplicationEvent>() {
        @Override
        public void onApplicationEvent(ApplicationEvent event) {
            events.add(event);
        }
    });
    this.context = application.run();
    assertThat(events, hasItem(isA(ApplicationPreparedEvent.class)));
    assertThat(events, hasItem(isA(ContextRefreshedEvent.class)));
}
项目:spring-cloud-commons    文件:RestartListener.java   
@Override
public void onApplicationEvent(ApplicationEvent input) {
    if (input instanceof ApplicationPreparedEvent) {
        this.event = (ApplicationPreparedEvent) input;
        if (this.context == null) {
            this.context = this.event.getApplicationContext();
        }
    }
    else if (input instanceof ContextRefreshedEvent) {
        if (this.context != null && input.getSource().equals(this.context)
                && this.event != null) {
            this.context.publishEvent(this.event);
        }
    }
    else {
        if (this.context != null && input.getSource().equals(this.context)) {
            this.context = null;
            this.event = null;
        }
    }
}
项目:whatsmars    文件:DubboHolderListener.java   
@Override
public void onApplicationEvent(ApplicationEvent event) {
    if (event instanceof ApplicationPreparedEvent) {
        if (running == Boolean.FALSE)
            running = Boolean.TRUE;
        if (holdThread == null) {
            holdThread = new Thread(new Runnable() {
                @Override
                public void run() {
                    if (LOGGER.isTraceEnabled()) {
                        LOGGER.trace(Thread.currentThread().getName());
                    }
                    while (running && !Thread.currentThread().isInterrupted()) {
                        try {
                            Thread.sleep(2000);
                        } catch (InterruptedException e) {
                        }
                    }
                }
            }, "Dubbo-Holder");
            holdThread.setDaemon(false);
            holdThread.start();
        }
    }
    if (event instanceof ContextClosedEvent) {
        running = Boolean.FALSE;
        if (null != holdThread) {
            holdThread.interrupt();
            holdThread = null;
        }
    }
}
项目:spring-boot-starter-dubbo    文件:DubboHolderListener.java   
@Override
public void onApplicationEvent(ApplicationEvent event) {
    if (event instanceof ApplicationPreparedEvent) {
        if (running == Boolean.FALSE)
            running = Boolean.TRUE;
        if (holdThread == null) {
            holdThread = new Thread(new Runnable() {
                @Override
                public void run() {
                    if (LOGGER.isTraceEnabled()) {
                        LOGGER.trace(Thread.currentThread().getName());
                    }
                    while (running && !Thread.currentThread().isInterrupted()) {
                        try {
                            Thread.sleep(2000);
                        } catch (InterruptedException e) {
                        }
                    }
                }
            }, "Dubbo-Holder");
            holdThread.setDaemon(false);
            holdThread.start();
        }
    }
    if (event instanceof ContextClosedEvent) {
        running = Boolean.FALSE;
        if (null != holdThread) {
            holdThread.interrupt();
            holdThread = null;
        }
    }
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:LoggingApplicationListener.java   
private void onApplicationPreparedEvent(ApplicationPreparedEvent event) {
    ConfigurableListableBeanFactory beanFactory = event.getApplicationContext()
            .getBeanFactory();
    if (!beanFactory.containsBean(LOGGING_SYSTEM_BEAN_NAME)) {
        beanFactory.registerSingleton(LOGGING_SYSTEM_BEAN_NAME, this.loggingSystem);
    }
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:ConfigFileApplicationListener.java   
@Override
public void onApplicationEvent(ApplicationEvent event) {
    if (event instanceof ApplicationEnvironmentPreparedEvent) {
        onApplicationEnvironmentPreparedEvent(
                (ApplicationEnvironmentPreparedEvent) event);
    }
    if (event instanceof ApplicationPreparedEvent) {
        onApplicationPreparedEvent(event);
    }
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:ApplicationPidFileWriter.java   
private Environment getEnvironment(SpringApplicationEvent event) {
    if (event instanceof ApplicationEnvironmentPreparedEvent) {
        return ((ApplicationEnvironmentPreparedEvent) event).getEnvironment();
    }
    if (event instanceof ApplicationPreparedEvent) {
        return ((ApplicationPreparedEvent) event).getApplicationContext()
                .getEnvironment();
    }
    return null;
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:ApplicationPidFileWriterTests.java   
private SpringApplicationEvent createPreparedEvent(String propName,
        String propValue) {
    ConfigurableEnvironment environment = createEnvironment(propName, propValue);
    ConfigurableApplicationContext context = mock(
            ConfigurableApplicationContext.class);
    given(context.getEnvironment()).willReturn(environment);
    return new ApplicationPreparedEvent(new SpringApplication(), new String[] {},
            context);
}
项目:haven-platform    文件:ConfigServerBootstrapApplicationListener.java   
@Override
public void onApplicationEvent(ApplicationPreparedEvent event) {
    ConfigurableEnvironment environment = event.getApplicationContext().getEnvironment();
    if (StringUtils.hasText(environment.resolvePlaceholders("${dm.config.git.uri:}"))) {
        if (!environment.getPropertySources().contains(this.propertySource.getName())) {
            environment.getPropertySources().addLast(this.propertySource);
        }
    }
}
项目:spring-boot-concourse    文件:LoggingApplicationListener.java   
private void onApplicationPreparedEvent(ApplicationPreparedEvent event) {
    ConfigurableListableBeanFactory beanFactory = event.getApplicationContext()
            .getBeanFactory();
    if (!beanFactory.containsBean(LOGGING_SYSTEM_BEAN_NAME)) {
        beanFactory.registerSingleton(LOGGING_SYSTEM_BEAN_NAME, this.loggingSystem);
    }
}
项目:spring-boot-concourse    文件:ConfigFileApplicationListener.java   
@Override
public void onApplicationEvent(ApplicationEvent event) {
    if (event instanceof ApplicationEnvironmentPreparedEvent) {
        onApplicationEnvironmentPreparedEvent(
                (ApplicationEnvironmentPreparedEvent) event);
    }
    if (event instanceof ApplicationPreparedEvent) {
        onApplicationPreparedEvent(event);
    }
}
项目:spring-boot-concourse    文件:ApplicationPidFileWriter.java   
private Environment getEnvironment(SpringApplicationEvent event) {
    if (event instanceof ApplicationEnvironmentPreparedEvent) {
        return ((ApplicationEnvironmentPreparedEvent) event).getEnvironment();
    }
    if (event instanceof ApplicationPreparedEvent) {
        return ((ApplicationPreparedEvent) event).getApplicationContext()
                .getEnvironment();
    }
    return null;
}
项目:spring-boot-concourse    文件:ApplicationPidFileWriterTests.java   
private SpringApplicationEvent createPreparedEvent(String propName,
        String propValue) {
    ConfigurableEnvironment environment = createEnvironment(propName, propValue);
    ConfigurableApplicationContext context = mock(
            ConfigurableApplicationContext.class);
    given(context.getEnvironment()).willReturn(environment);
    return new ApplicationPreparedEvent(new SpringApplication(), new String[] {},
            context);
}
项目:contestparser    文件:SpringApplicationTests.java   
@Test
public void registerListener() throws Exception {
    SpringApplication application = new SpringApplication(ExampleConfig.class);
    application.setApplicationContextClass(SpyApplicationContext.class);
    final LinkedHashSet<ApplicationEvent> events = new LinkedHashSet<ApplicationEvent>();
    application.addListeners(new ApplicationListener<ApplicationEvent>() {
        @Override
        public void onApplicationEvent(ApplicationEvent event) {
            events.add(event);
        }
    });
    this.context = application.run();
    assertThat(events, hasItem(isA(ApplicationPreparedEvent.class)));
    assertThat(events, hasItem(isA(ContextRefreshedEvent.class)));
}
项目:contestparser    文件:ApplicationPidFileWriter.java   
private Environment getEnvironment(SpringApplicationEvent event) {
    if (event instanceof ApplicationEnvironmentPreparedEvent) {
        return ((ApplicationEnvironmentPreparedEvent) event).getEnvironment();
    }
    if (event instanceof ApplicationPreparedEvent) {
        return ((ApplicationPreparedEvent) event).getApplicationContext()
                .getEnvironment();
    }
    return null;
}
项目:contestparser    文件:ApplicationPidFileWriterTests.java   
private SpringApplicationEvent createPreparedEvent(String propName,
        String propValue) {
    ConfigurableEnvironment environment = createEnvironment(propName, propValue);
    ConfigurableApplicationContext context = mock(
            ConfigurableApplicationContext.class);
    given(context.getEnvironment()).willReturn(environment);
    return new ApplicationPreparedEvent(new SpringApplication(), new String[] {},
            context);
}
项目:osiam    文件:OsiamHome.java   
@Override
public void onApplicationEvent(ApplicationEvent event) {
    if (event instanceof ApplicationEnvironmentPreparedEvent) {
        ConfigurableEnvironment environment = ((ApplicationEnvironmentPreparedEvent) event).getEnvironment();
        configure(environment);
        if(shouldInitializeHome) {
            initialize();
        }
    } else if (event instanceof ApplicationPreparedEvent) {
        writeLogs();
    }
}
项目:spring-cloud-commons    文件:RestartListener.java   
@Override
public boolean supportsEventType(Class<? extends ApplicationEvent> eventType) {
    return ApplicationPreparedEvent.class.isAssignableFrom(eventType)
            || ContextRefreshedEvent.class.isAssignableFrom(eventType)
            || ContextClosedEvent.class.isAssignableFrom(eventType);

}
项目:spring-cloud-commons    文件:RestartEndpoint.java   
@Override
public void onApplicationEvent(ApplicationPreparedEvent input) {
    this.event = input;
    if (this.context == null) {
        this.context = this.event.getApplicationContext();
        this.args = this.event.getArgs();
        this.application = this.event.getSpringApplication();
    }
}
项目:spring-boot-starter-batch-web    文件:JobLoggingApplicationListener.java   
@Override
public void onApplicationEvent(ApplicationPreparedEvent event) {
        String jobLogPath = event.getApplicationContext().getEnvironment().getProperty("batch.joblog.path");
        if (!StringUtils.isEmpty(jobLogPath)) {
                if (!jobLogPath.endsWith("/")) {
                        jobLogPath = jobLogPath + "/";
                }
                System.setProperty("JOB_LOG_PATH", jobLogPath);
        }
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:ConfigFileApplicationListener.java   
private void onApplicationPreparedEvent(ApplicationEvent event) {
    this.logger.replayTo(ConfigFileApplicationListener.class);
    addPostProcessors(((ApplicationPreparedEvent) event).getApplicationContext());
}
项目:spring-boot-concourse    文件:ConfigFileApplicationListener.java   
private void onApplicationPreparedEvent(ApplicationEvent event) {
    this.logger.replayTo(ConfigFileApplicationListener.class);
    addPostProcessors(((ApplicationPreparedEvent) event).getApplicationContext());
}
项目:contestparser    文件:ConfigFileEnvironmentPostProcessor.java   
@Override
public void onApplicationEvent(ApplicationPreparedEvent event) {
    this.logger.replayTo(ConfigFileEnvironmentPostProcessor.class);
    addPostProcessors(event.getApplicationContext());
}
项目:cylus    文件:DockerSecretEnvironmentPostProcessor.java   
@Override
public void onApplicationEvent(final ApplicationPreparedEvent event) {
    //LOGGER.replayTo(DockerSecretEnvironmentPostProcessor.class);
}