- admin监控
- admin的service端
- pom.xml
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-server</artifactId>
</dependency>
- application.yml
spring:
application:
name: admin-server
server:
port: 9090
- springboot入口文件出加入@EnableAdminServer注解
- admin的Client端
- pom.xml
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
</dependency>
- application.yml
server:
port: 8080
spring:
application:
name: Admin Client
boot:
admin:
client:
url: http://localhost:9090
management:
endpoints:
web:
exposure:
include: '*'
运行结果

2. eureka的service端
- pom.xml
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
- application.yml
server:
port: 8000 # 你的端口
eureka:
instance:
hostname: localhost # 你的地址
client:
registerWithEureka: false # 表示是否注册自身到eureka服务器,因为当前这个应用就是eureka服务器,没必要注册自身,所以这里是false
fetchRegistry: false # fetchRegistry表示是否从eureka服务器获取注册信息
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
# defaultZone就比较重要了,是设置eureka服务器所在的地址,查询服务和注册服务都需要依赖这个地址。
- springboot入口文件处加入@EnableEurekaServer注解
- eureka的Client端
- pom.xml
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
- application.yml
server:
port: 8001 # 你的端口
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8000/eureka/ # 服务中心地址
spring:
application:
name: orcl # 客户端的名字
- springboot入口文件处加入@EnableEurekaClient注解
运行结果

本文介绍了如何在SpringBoot应用中集成Admin监控和Eureka服务发现。首先,详细讲述了admin服务端的配置,包括pom.xml依赖、application.yml设置以及启用@EnableAdminServer注解。接着,讨论了admin客户端的配置,同样涵盖pom.xml、application.yml和@EnableEurekaClient注解的使用。然后,转向Eureka服务端,说明了启用@EnableEurekaServer注解的步骤。最后,提到了Eureka客户端的配置和启用。通过这些步骤,实现了对SpringBoot应用的全面监控和注册到Eureka服务中心。
11万+

被折叠的 条评论
为什么被折叠?



