参考
https://www.cnblogs.com/shihaiming/p/8488939.html
代码地址
https://gitee.com/skydreamfei/spring-cloud-examples
服务端 设置
将eureka注册中心服务加入监管
- 添加依赖
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server</artifactId>
<version>1.5.6</version>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server-ui</artifactId>
<version>1.5.6</version>
</dependency>
</dependencies>
- 配置文件设置
server:
port: 8000
spring:
application:
name: admin-server
eureka:
instance:
leaseRenewalIntervalInSeconds: 10
client:
registryFetchIntervalSeconds: 5
serviceUrl:
# 注册地址设置
defaultZone: ${EUREKA_SERVICE_URL:http://localhost:8761}/eureka/
management.security.enabled: false
- 启动配置
@Configuration
@EnableAutoConfiguration
@EnableDiscoveryClient
@EnableAdminServer
public class AdminServerApplication {
public static void main(String[] args) {
SpringApplication.run(AdminServerApplication.class, args);
}
}
- 效果 浏览器访问http://localhost:8000
客户端设置, 单个服务加入监控
1. 设置依赖
<dependencies>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
<version>1.5.6</version>
</dependency>
</dependencies>
2. 设置配置信息
server.port=8001
# 配置Admin Server的地址
spring.boot.admin.url=http://localhost:8000
# 关闭安全验证
management.security.enabled=false
3. 启动
@SpringBootApplication
public class AdminClientApplication {
public static void main(String[] args) {
SpringApplication.run(AdminClientApplication.class, args);
}
}
-
效果
客户端 使用eureka注册中心注册到admin
和服务注册到eureka配置一样,不再细说。
邮件发送配置
没用到,先不写了