通过Eureka、DiscoveryClient实现Spring Boot Admin管理功能
来源:互联网 发布:2016电脑安全软件排行 编辑:程序博客网 时间:2024/06/05 09:10
Spring Boot Admin 文档在github,我主要是根据这篇文档的2.2.2. Spring Cloud Discovery进行了简单的整理。
1. 建空maven-demo项目
选择maven-demo后,不勾选内容,填好下一步的内容,然后创建即可。
2. 新建eureka-server模块
在maven-demo项目上【右键】,【New】–>【Module】,选择【Spring Initializr】–>【Default】
在【Dependencies】中默认选【Cloud Discovery】–>【Eureka Server】,下一步,创建即可
【pom】文件不动
EurekaServerApplication.java
@SpringBootApplication@EnableEurekaServerpublic class EurekaServerApplication { public static void main(String[] args) { SpringApplication.run(EurekaServerApplication.class, args); }}
application.yml
server: port: 8761eureka: server: enable-self-preservation: false #关闭自我保护 eviction-interval-timer-in-ms: 4000 #清理间隔(单位毫秒) instance: hostname: localhost client: register-with-eureka: false fetch-registry: false service-url: defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/management: port: 8770 security: enabled: false
3. 新建admin-server模块
在maven-demo项目上【右键】,【New】–>【Module】,选择【Spring Initializr】–>【Default】
在【Dependencies】中默认选【core】,下一步,创建即可
在【pom】文件中添加一下三项依赖
<dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-server</artifactId> <version>1.5.4</version> </dependency> <dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-server-ui</artifactId> <version>1.5.4</version> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka</artifactId> <version>1.2.6.RELEASE</version> </dependency>
【注意】,由于我使用的是在线生成Spring 项目,spring-boot-starter-parent版本会是(当前)最新版1.5.8,所以,spring-boot-admin-server和spring-boot-admin-server-ui也要用最新的版本,否则会出现错误
java.lang.NoClassDefFoundError: org/springframework/boot/context/embedded/ServletRegistrationBean
我个人在出此编辑的时候就是将spring-boot-admin-server和spring-boot-admin-server-ui的版本使用成了1.3.4结果一直出现这个问题,后来换成1.5.4就OK了。
AdminServerApplication.java
@EnableAdminServer@Configuration@EnableDiscoveryClient@EnableAutoConfigurationpublic class AdminServerApplication { public static void main(String[] args) { SpringApplication.run(AdminServerApplication.class, args); }}
【注意】在这里不要添加@SpringBootApplication注解,否则在启动后,并不能发现注册在Eureka的服务。
application.yml
server: port: 8090spring: application: name: Spring Boot Admin Server index: 1 jackson: serialization: indent_output: true boot: admin: url: http://localhost:${server.port}management: security: enabled: false context-path: /manageendpoints: health: sensitive: falseeureka: instance: instance-id: ${spring.application.name}:${spring.application.index:${random.value}} prefer-ip-address: true hostname: eureka-client-${spring.application.index} status-page-url-path: ${management.context-path}/info health-check-url-path: ${management.context-path}/health metadata-map: management: context-path: ${management.context-path} client: service-url: defaultZone: http://localhost:8761/eureka/
4. 创建admin-eureka-client模块
在maven-demo项目上【右键】,【New】–>【Module】,选择【Spring Initializr】–>【Default】
在【Dependencies】中默认选【Cloud Discovery】–>【Eureka Discovery】,下一步,创建即可
在【pom】文件中添加一项依赖:
<dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> <version>1.5.8.RELEASE</version> </dependency> </dependencies>
AdminEurekaClientApplication.java
@SpringBootApplication@EnableEurekaClientpublic class AdminEurekaClientApplication { public static void main(String[] args) { SpringApplication.run(AdminEurekaClientApplication.class, args); }}
application.yml
spring: application: name: admin-client index: 1server: port: 8080eureka: instance: instance-id: ${spring.application.name}:${spring.application.index:${random.value}} prefer-ip-address: true hostname: eureka-client-${spring.application.index} status-page-url-path: ${management.context-path}/info health-check-url-path: ${management.context-path}/health metadata-map: management: context-path: ${management.context-path} client: service-url: defaultZone: http://localhost:8761/eureka/management: security: enabled: false context-path: /manage
启动
依次启动各模块,在浏览器中输入http://localhost:8761/,弹出以下界面
可以发现admin-server和admin-eureka-client模块均已在eureka-server注册成功
在浏览器中输入http://localhost:8090,弹出以下界面
发现admin-eureka-client已经加入到监控中,点击右侧的【Details】,可以观察其他详细内容:
以上就是本次Spring Boot Admin和Eureka结合实现监控的小demo,欢迎大家指正。
源码:spring-boot-admin-eureka
- 通过Eureka、DiscoveryClient实现Spring Boot Admin管理功能
- Spring boot Admin 使用eureka监控服务
- Spring-boot-admin功能说明
- Spring-boot-admin功能说明
- Spring cloud eureka+Client+Spring boot admin 服务注册监控
- spring boot 通过Eureka搭建微服务
- Spring Boot Admin管理监控数据
- Spring Boot Admin管理监控数据
- SpringBoot Admin 通过eureka 监控服务
- Spring Boot Admin
- Spring Boot Admin实践
- Spring boot admin介绍
- Spring Boot Admin Reference Guide
- Spring Boot Admin 的使用
- Spring Boot Admin的使用
- Spring Boot Admin 的使用
- Spring Boot Admin 的使用
- Spring Boot Admin的使用
- 韩信点兵(中国剩余定理)
- Mybatis分页插件PageHelper用法
- Mac OS X 安装和配置 PAServer(JVM),调试Firemonkey程序
- jmeter之ant配置批量执行用例发送邮件
- 深入MNIST(2)
- 通过Eureka、DiscoveryClient实现Spring Boot Admin管理功能
- 安装QNX SDP6.5.0遇到Exception in thread “mian” java.long问题
- Spring中的事务管理
- C++标准库简洁索引
- JAVA异常之运行时异常和非运行时异常
- 前端面试总结之前端性能优化( http css JavaScript images HTML)
- [备忘录]-Ubuntu使用阿里云软件源
- Ubuntu操作系统,出现不能识别优盘的情况,简单几步操作即可解决。
- android,使用高德地图SDk(地图SDK,定位SDK,搜索SDK),显示当前位置以及自定义多个Markers