spring boot admin 监控 spring cloud服务
spring boot admin 服务端
1. pom 文件
父pom dependencyManagement
<dependencyManagement>
<dependencies>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-dependencies
</artifactId>
<version>
Greenwich.RELEASE
</version>
<type>
pom
</type>
<scope>
import
</scope>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-dependencies</artifactId>
<version>2.1.2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
spring boot admin 服务端 pom
运行时会报错,但不影响运行 java.lang.IllegalStateException: Calling [asyncError()] is not valid for a request with Async state [MUST_DISPATCH] 打开注释可以解决
<dependencies>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<!--<exclusions>-->
<!--<exclusion>-->
<!--<groupId>org.springframework.boot</groupId>-->
<!--<artifactId>spring-boot-starter-tomcat</artifactId>-->
<!--</exclusion>-->
<!--</exclusions>-->
</dependency>
<!--<dependency>-->
<!--<groupId>org.springframework.boot</groupId>-->
<!--<artifactId>spring-boot-starter-jetty</artifactId>-->
<!--</dependency>-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
</dependencies>
2.application.properties
spring.application.name=cloudadminserver
server.port=8095
eureka.instance.hostname=localhost
eureka.client.service-url.defaultZone=http://localhost:8080/eureka/
#注册表获取间隔时间(秒)
#eureka.client.registry-fetch-interval-seconds=5
#eureka.instance.leaseRenewalIntervalInSeconds=10
#eureka.instance.metadata-map.startup=${random.int}
#
##暴露actuator的所有端点
management.endpoints.web.exposure.include=*
##health endpoint是否必须显示全部细节。默认情况下, /actuator/health 是公开的,并且不显示细节
management.endpoint.health.show-details=always
3.代码部分
@SpringBootApplication
@EnableAdminServer
@EnableEurekaClient
public class SpringCloudAdminServerApplication {
public static void main(String[] args) {
SpringApplication.run(SpringCloudAdminServerApplication.class, args);
}
}
spring cloud服务提供者部分
1.原pom基础上添加依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
2.application.properties 原配置基础上添加属性
#暴露actuator的所有端点
management.endpoints.web.exposure.include=*
#health endpoint是否必须显示全部细节。默认情况下, /actuator/health 是公开的,并且不显示细节
management.endpoint.health.show-details=always
运行结果