Spring Boot Admin 是一个管理和监控Spring Boot 应用程序的可视化监控软件
1.而在springboot中使用起来也十分方便,首先我们先添加web依赖和Spring Boot Admin依赖
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-server</artifactId>
<version>2.0.2</version>
</dependency>
</dependencies>
然后我们再在项目的启动类上添加@EnableAdminServer注解
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import de.codecentric.boot.admin.server.config.EnableAdminServer;
@SpringBootApplication
@EnableAdminServer
public class SpringBootAdminApplication {
public static void main(String[] args) {
SpringApplication.run(SpringBootAdminApplication.class, args);
}
}
这样在项目启动的时候就自动启动了springbootadmin,接下来运行项目,然后在浏览器上输入http://localhost:8080/#/applications就可以看到这个页面
2.然后我们再创建另一个项目,并把它注册进我们的Spring Boot Admin 里面
首先我们先添加依赖
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
<version>2.0.2</version>
</dependency>
然后再在我们的application.properties里面进行配置
management.endpoints.web.exposure.include=*
management.endpoints.web.cors.allowed-origins=*
management.endpoints.web.cors.allowed-methods==GET,POST
management.endpoint.health.show-details=always
info.author.name=A517
server.port=8081
spring.boot.admin.client.url=http://localhost:8080
首先我们的client项目的端口号要进行修改,然后通过配置
1.management.endpoints.web.exposure.include=*//暴露端口信息
2.management.endpoints.web.cors.allowed-origins=*//允许跨域
3.management.endpoints.web.cors.allowed-methods==GET,POST//允许方法
4.management.endpoint.health.show-details=always//通过权限配置,有never和when-authorized和always三种属性来进行查看权限
然后运行项目,就会看到项目的信息已被注册进去
不过如果在client项目配置了安全框架的话,在安全配置哪里把client的.antMatchers("/actuator/**").permitAll()给暴露就好了,
这就是springbootadmin的简单使用