Spring Boot starter that auto-configures a client application to register with Spring Boot Admin server for centralized monitoring and management
—
Application registration provides programmatic control over how and when a Spring Boot application registers itself with Spring Boot Admin servers. While automatic registration is the default behavior, you can manually control the registration process for advanced use cases.
public interface ApplicationRegistrator {
/**
* Registers the client application at spring-boot-admin-server.
* @return true if successful registration on at least one admin server
*/
boolean register();
/**
* Tries to deregister currently registered application
*/
void deregister();
/**
* @return the id of this client as given by the admin server.
* Returns null if the client has not registered against the admin server yet.
*/
String getRegisteredId();
}public class Application {
// Create a new application builder
public static Builder create(String name);
// Application properties (all immutable)
public String getName();
public String getManagementUrl();
public String getHealthUrl();
public String getServiceUrl();
public Map<String, String> getMetadata();
public static class Builder {
public Builder name(String name);
public Builder managementUrl(String managementUrl);
public Builder healthUrl(String healthUrl);
public Builder serviceUrl(String serviceUrl);
public Builder metadata(String key, String value);
public Builder metadata(Map<String, String> metadata);
public Application build();
}
}public interface ApplicationFactory {
/**
* Create an Application instance from current configuration
*/
Application createApplication();
}public class DefaultApplicationRegistrator implements ApplicationRegistrator {
public DefaultApplicationRegistrator(
ApplicationFactory applicationFactory,
RegistrationClient registrationClient,
String[] adminUrl,
boolean registerOnce
);
}public class RegistrationApplicationListener {
public void setAutoRegister(boolean autoRegister);
public void setAutoDeregister(boolean autoDeregister);
public void setRegisterPeriod(Duration registerPeriod);
}public interface RegistrationClient {
/**
* Register application with admin server
* @param adminUrl The admin server URL
* @param self The application to register
* @return Registration ID from server
*/
String register(String adminUrl, Application self);
/**
* Deregister application from admin server
* @param adminUrl The admin server URL
* @param id The registration ID
*/
void deregister(String adminUrl, String id);
}public class BlockingRegistrationClient implements RegistrationClient {
public BlockingRegistrationClient(RestTemplate restTemplate);
}public class ReactiveRegistrationClient implements RegistrationClient {
public ReactiveRegistrationClient(WebClient webClient, Duration timeout);
}@Component
public class CustomRegistrationService {
private final ApplicationRegistrator registrator;
public CustomRegistrationService(ApplicationRegistrator registrator) {
this.registrator = registrator;
}
public void registerWithAdminServer() {
boolean success = registrator.register();
if (success) {
String registrationId = registrator.getRegisteredId();
log.info("Successfully registered with ID: {}", registrationId);
} else {
log.warn("Failed to register with admin server");
}
}
public void unregisterFromAdminServer() {
registrator.deregister();
log.info("Deregistered from admin server");
}
}@Component
public class CustomApplicationFactory implements ApplicationFactory {
private final InstanceProperties instanceProperties;
public CustomApplicationFactory(InstanceProperties instanceProperties) {
this.instanceProperties = instanceProperties;
}
@Override
public Application createApplication() {
return Application.create(instanceProperties.getName())
.serviceUrl("https://my-service.example.com")
.managementUrl("https://my-service.example.com/actuator")
.healthUrl("https://my-service.example.com/actuator/health")
.metadata("custom-tag", "custom-value")
.metadata("build-time", Instant.now().toString())
.build();
}
}@Component
@ConditionalOnProperty(value = "app.admin.registration.enabled", havingValue = "true")
public class ConditionalRegistrationService {
private final ApplicationRegistrator registrator;
private final Environment environment;
public ConditionalRegistrationService(
ApplicationRegistrator registrator,
Environment environment) {
this.registrator = registrator;
this.environment = environment;
}
@EventListener(ApplicationReadyEvent.class)
public void onApplicationReady() {
if (shouldRegister()) {
registrator.register();
}
}
@EventListener(ContextClosedEvent.class)
public void onApplicationClosed() {
registrator.deregister();
}
private boolean shouldRegister() {
String[] profiles = environment.getActiveProfiles();
return Arrays.asList(profiles).contains("production");
}
}To take full manual control, disable automatic registration:
# Disable automatic registration
spring.boot.admin.client.auto-registration=false
spring.boot.admin.client.auto-deregistration=falseThen implement your own registration logic as shown in the examples above.
Registration failures are logged but do not prevent application startup. The client will continue to retry registration based on the configured period until successful or the application shuts down.
Install with Tessl CLI
npx tessl i tessl/maven-de-codecentric--spring-boot-admin-starter-client