Example usage for org.springframework.boot.context.event ApplicationReadyEvent getApplicationContext

List of usage examples for org.springframework.boot.context.event ApplicationReadyEvent getApplicationContext

Introduction

In this page you can find the example usage for org.springframework.boot.context.event ApplicationReadyEvent getApplicationContext.

Prototype

public ConfigurableApplicationContext getApplicationContext() 

Source Link

Document

Return the application context.

Usage

From source file:com.example.config.BeanCountingApplicationListener.java

@SuppressWarnings("resource")
@Override/*from   www. j a v a 2 s.c o m*/
public void onApplicationEvent(ApplicationReadyEvent event) {
    if (!event.getApplicationContext().equals(this.context)) {
        return;
    }
    int count = 0;
    ConfigurableApplicationContext context = event.getApplicationContext();
    String id = context.getId();
    List<String> names = new ArrayList<>();
    while (context != null) {
        count += context.getBeanDefinitionCount();
        names.addAll(Arrays.asList(context.getBeanDefinitionNames()));
        context = (ConfigurableApplicationContext) context.getParent();
    }
    logger.info("Bean count: " + id + "=" + count);
    logger.debug("Bean names: " + id + "=" + names);
    try {
        logger.info("Class count: " + id + "="
                + ManagementFactory.getClassLoadingMXBean().getTotalLoadedClassCount());
    } catch (Exception e) {
    }
}

From source file:com.example.config.StartupApplicationListener.java

@Override
public void onApplicationEvent(ApplicationReadyEvent event) {
    if (!event.getApplicationContext().equals(this.context)) {
        return;/*from   w  w  w  .  j  av  a2 s.com*/
    }
    if (isSpringBootApplication(sources(event))) {
        try {
            logger.info(MARKER);
        } catch (Exception e) {
        }
    }
}

From source file:de.codecentric.boot.admin.services.RegistrationApplicationListener.java

@EventListener
@Order(Ordered.LOWEST_PRECEDENCE)/*ww w.j  av  a2s .c  o  m*/
public void onApplicationReady(ApplicationReadyEvent event) {
    if (event.getApplicationContext().getParent() == null && autoRegister) {
        startRegisterTask();
    }
}

From source file:me.j360.trace.server.brave.BootstrapTrace.java

public void record(ApplicationEvent event) {
    annotations.put(event.getClass().getSimpleName().replace("Event", ""), timestamp + microsSinceInit());
    // record duration and flush the trace if we're done
    if (event instanceof ApplicationReadyEvent) {
        long duration = microsSinceInit(); // get duration now, as below logic might skew things.
        ApplicationReadyEvent ready = (ApplicationReadyEvent) event;
        try {//from  w w  w. jav  a  2s.c  om
            LocalTracer tracer = ready.getApplicationContext().getBeanFactory().getBean(Brave.class)
                    .localTracer();

            tracer.startNewSpan("spring-boot", "bootstrap", timestamp);
            annotations.forEach(tracer::submitAnnotation);
            tracer.finishSpan(duration);
        } catch (NoSuchBeanDefinitionException ignored) {
            // Brave is optional
        }
    }
}

From source file:de.codecentric.boot.admin.config.AdminClientProperties.java

@EventListener
public void onApplicationReady(ApplicationReadyEvent event) {
    if (event.getApplicationContext().getParent() == null) {
        serverPort = event.getApplicationContext().getEnvironment().getProperty("local.server.port",
                Integer.class);
        managementPort = event.getApplicationContext().getEnvironment().getProperty("local.management.port",
                Integer.class, serverPort);
    }//from www . ja  v  a 2 s. c  om
}

From source file:org.springframework.boot.devtools.autoconfigure.ConditionEvaluationDeltaLoggingListener.java

@Override
public void onApplicationEvent(ApplicationReadyEvent event) {
    ConditionEvaluationReport report = event.getApplicationContext().getBean(ConditionEvaluationReport.class);
    if (previousReport != null) {
        ConditionEvaluationReport delta = report.getDelta(previousReport);
        if (!delta.getConditionAndOutcomesBySource().isEmpty() || !delta.getExclusions().isEmpty()
                || !delta.getUnconditionalClasses().isEmpty()) {
            if (this.logger.isInfoEnabled()) {
                this.logger.info("Condition evaluation delta:"
                        + new ConditionEvaluationReportMessage(delta, "CONDITION EVALUATION DELTA"));
            }/*from   w  w  w  .jav a2 s. c  o m*/
        } else {
            this.logger.info("Condition evaluation unchanged");
        }
    }
    previousReport = report;
}