[BAEL-5110] Actuator endpoint for startup tracking (#11351)
This commit is contained in:
parent
f200ce5b14
commit
82572378b2
|
@ -0,0 +1,17 @@
|
||||||
|
package com.baeldung.startup;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class ResourceInitializer {
|
||||||
|
|
||||||
|
ResourceInitializer() throws Exception {
|
||||||
|
// simulate resource init with random delay of a few seconds
|
||||||
|
int randomDelay = ThreadLocalRandom.current().nextInt(5, 9);
|
||||||
|
TimeUnit.SECONDS.sleep(randomDelay);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
package com.baeldung.startup;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.actuate.autoconfigure.security.servlet.ManagementWebSecurityAutoConfiguration;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
|
||||||
|
import org.springframework.boot.context.metrics.buffering.BufferingApplicationStartup;
|
||||||
|
|
||||||
|
import static java.lang.Boolean.FALSE;
|
||||||
|
|
||||||
|
@SpringBootApplication(exclude = {
|
||||||
|
SecurityAutoConfiguration.class,
|
||||||
|
ManagementWebSecurityAutoConfiguration.class}
|
||||||
|
)
|
||||||
|
public class StartupTrackingApplication {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// only load properties for this application
|
||||||
|
System.setProperty("spring.config.location", "classpath:application-startup.properties");
|
||||||
|
|
||||||
|
SpringApplication app = new SpringApplication(StartupTrackingApplication.class);
|
||||||
|
BufferingApplicationStartup startup = new BufferingApplicationStartup(2048);
|
||||||
|
|
||||||
|
if (shouldFilterSteps()) {
|
||||||
|
startup.addFilter(startupStep -> startupStep.getName().matches("spring.beans.instantiate"));
|
||||||
|
}
|
||||||
|
|
||||||
|
app.setApplicationStartup(startup);
|
||||||
|
app.run(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean shouldFilterSteps() {
|
||||||
|
return Boolean.parseBoolean(
|
||||||
|
System.getProperty("startup.steps.filter", FALSE.toString())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
management.endpoints.web.exposure.include=startup
|
||||||
|
|
||||||
|
# JPA is not required for startup actuator endpoint
|
||||||
|
spring.autoconfigure.exclude= org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration, \
|
||||||
|
org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration, \
|
||||||
|
org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration
|
Loading…
Reference in New Issue