- 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注解
运行结果