spring-boot-admin-docs/src/site/docs/03-client/40-service-discovery.md
Spring Boot Admin integrates seamlessly with Spring Cloud Discovery services, allowing automatic registration without the Spring Boot Admin Client library.
When using service discovery, the Admin Server discovers applications automatically through the discovery client. This eliminates the need for:
Add Eureka Client to your Admin Server:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
Enable discovery in your Admin Server:
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import de.codecentric.boot.admin.server.config.EnableAdminServer;
@EnableDiscoveryClient
@EnableAdminServer
@SpringBootApplication
public class SpringBootAdminApplication {
static void main(String[] args) {
SpringApplication.run(SpringBootAdminApplication.class, args);
}
}
Configure Eureka connection:
spring:
application:
name: spring-boot-admin-server
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
registryFetchIntervalSeconds: 5
instance:
leaseRenewalIntervalInSeconds: 10
health-check-url-path: /actuator/health
management:
endpoints:
web:
exposure:
include: "*"
endpoint:
health:
show-details: ALWAYS
Add Eureka Client to your application (no Admin Client needed):
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
Enable discovery:
@EnableDiscoveryClient
@SpringBootApplication
public class MyApplication {
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
}
Configure Eureka and expose endpoints:
spring:
application:
name: my-application
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
instance:
leaseRenewalIntervalInSeconds: 10
health-check-url-path: /actuator/health
metadata-map:
startup: ${random.int} # Triggers info update on restart
user.name: ${spring.security.user.name} # For secured actuators
user.password: ${spring.security.user.password}
management:
endpoints:
web:
exposure:
include: "*"
endpoint:
health:
show-details: ALWAYS
Add custom metadata through Eureka:
eureka:
instance:
metadata-map:
startup: ${random.int}
tags.environment: production
tags.region: us-east-1
team: platform
version: ${spring.application.version}
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-discovery</artifactId>
</dependency>
@EnableDiscoveryClient
@EnableAdminServer
@SpringBootApplication
public class SpringBootAdminApplication {
static void main(String[] args) {
SpringApplication.run(SpringBootAdminApplication.class, args);
}
}
spring:
application:
name: spring-boot-admin-server
cloud:
consul:
host: localhost
port: 8500
discovery:
prefer-ip-address: true
health-check-interval: 10s
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-discovery</artifactId>
</dependency>
spring:
application:
name: my-application
cloud:
consul:
host: localhost
port: 8500
discovery:
metadata:
user-name: ${spring.security.user.name} # Note: dashes not dots!
user-password: ${spring.security.user.password}
environment: production
management-context-path: ${management.server.base-path:/actuator}
management:
endpoints:
web:
exposure:
include: "*"
:::warning
Consul does not allow dots (.) in metadata keys. Use dashes (-) or underscores (_) instead:
user-name or user_nameuser.name
:::<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zookeeper-discovery</artifactId>
</dependency>
spring:
application:
name: spring-boot-admin-server
cloud:
zookeeper:
connect-string: localhost:2181
discovery:
enabled: true
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zookeeper-discovery</artifactId>
</dependency>
spring:
application:
name: my-application
cloud:
zookeeper:
connect-string: localhost:2181
discovery:
metadata:
user.name: ${spring.security.user.name}
user.password: ${spring.security.user.password}
management.context-path: /actuator
By default, the Admin Server monitors all discovered services. You can filter services using the InstanceFilter
interface.
spring:
boot:
admin:
discovery:
ignored-services: consul,eureka,zookeeper # Don't monitor discovery services
import de.codecentric.boot.admin.server.domain.values.Registration;
import de.codecentric.boot.admin.server.services.InstanceFilter;
import org.springframework.stereotype.Component;
@Component
public class CustomInstanceFilter implements InstanceFilter {
@Override
public boolean test(Registration registration) {
String name = registration.getName();
// Ignore internal services
if (name.startsWith("internal-")) {
return false;
}
// Only monitor services with specific metadata
String monitorable = registration.getMetadata().get("monitorable");
if (!"true".equals(monitorable)) {
return false;
}
return true;
}
}
When multiple instances of the same service exist, configure which instance URL to use:
spring:
boot:
admin:
discovery:
instance-prefer-ip: true # Use IP instead of hostname
If your management endpoints are on a different port or path:
management:
server:
port: 9090 # Management on different port
base-path: /management
eureka:
instance:
metadata-map:
management.port: 9090
management.context-path: /management
Configure health check paths for discovery:
eureka:
instance:
health-check-url-path: /actuator/health
health-check-url: http://my-app.example.com/actuator/health
status-page-url-path: /actuator/info
home-page-url: /
Discovery services may return different URLs for the service and management endpoints:
eureka:
instance:
metadata-map:
management.context-path: /actuator # Management endpoint path
service-url: https://my-app.example.com # Public service URL
management-url: http://internal-app:8080/actuator # Internal mgmt URL
Pass credentials through metadata:
eureka:
instance:
metadata-map:
user.name: admin
user.password: ${ACTUATOR_PASSWORD}
Or configure on the Admin Server:
spring:
boot:
admin:
instance-auth:
enabled: true
default-user-name: admin
default-password: ${DEFAULT_PASSWORD}
service-map:
my-application:
user-name: app-admin
user-password: ${APP_PASSWORD}
You can use both service discovery and direct client registration simultaneously:
spring:
boot:
admin:
client:
url: http://localhost:8080 # Direct registration
auto-registration: true
eureka:
client:
enabled: true # Also register with Eureka
This provides redundancy if one registration method fails.
Check Discovery Registration:
# For Eureka
curl http://localhost:8761/eureka/apps
Verify Admin Server Discovery Client: Ensure @EnableDiscoveryClient is present
Check Network Connectivity: Admin Server must reach discovery service
Review Metadata: Ensure management URLs are correct
Set explicit management metadata:
eureka:
instance:
metadata-map:
management.port: ${management.server.port}
management.context-path: ${management.server.base-path}
Ensure health endpoint is accessible:
management:
endpoint:
health:
show-details: ALWAYS
endpoints:
web:
exposure:
include: health,info