How to Enable Nacos Service Discovery with Spring Boot Admin After Startup
After integrating Nacos as the service registry with Spring Boot Admin, the author discovered that only services started before the admin were monitored, examined how Eureka and Consul handle HeartbeatEvent, and resolved the issue by copying and configuring NacosWatch code from the official spring‑cloud‑alibaba repository, enabling automatic service registration.
Introduction
The author is rebuilding microservices in a new company, choosing Nacos as the service registry instead of Eureka, and using Mica as the microservice core. The source code is available at https://gitee.com/596392912/mica.
Problem
After integrating Nacos with Spring Boot Admin, only services started before the admin are monitored. Spring Boot Admin relies on
HeartbeatEventfor new service registration. The author notes that Eureka and Consul clients also send this event.
Eureka
Consul
Solution
The author initially considered implementing the feature and submitting it upstream, but discovered that the official
spring-cloud-alibabarepository already includes the functionality. Since it has not been released yet, the author copied the relevant code into their own project.
Copy NacosWatch
Note that there may be errors; you can hard‑code the required properties.
<code>
/**
* watch delay,duration to pull new service from nacos server.
*/
private long watchDelay = 30000;
</code>Add NacosWatch Auto‑Configuration
<code>
/**
* NacosWatch auto‑configuration
*
* @author L.cm
*/
@Configuration
public class NacosWatchAutoConfiguration {
@Bean
@ConditionalOnMissingBean
@ConditionalOnProperty(value = "spring.cloud.nacos.discovery.watch.enabled", matchIfMissing = true)
public NacosWatch nacosWatch(NacosDiscoveryProperties nacosDiscoveryProperties) {
return new NacosWatch(nacosDiscoveryProperties);
}
}
</code>Restart Spring Boot Admin, then start the other services; the new services are automatically synchronized to Spring Boot Admin—success!
Java Architecture Diary
Committed to sharing original, high‑quality technical articles; no fluff or promotional content.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.