springboot 集成 Spring Boot Admin
1.什么是Spring Boot Admin
Spring Boot Admin主要是用于管理和监控SpringBoot的应用,应用程序可以通过Spring Boot Admin Client向Admin Server进行注册或者使用Eureka、Consul这样的Spring Cloud注册中心来发现。
2.配置Spring Boot Admin Server
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server-ui</artifactId>
<version>2.3.1</version>
</dependency>
</dependencies>
server:
port: 8090
spring:
application:
name: admin-server
@Configuration
@EnableAutoConfiguration
@EnableAdminServer
public class AdminServerApplication {
public static void main(String[] args) {
SpringApplication.run(AdminServerApplication.class,args);
}
}
2.配置Spring Boot Admin client
<dependencies>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
<version>2.3.1</version>
</dependency>
<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>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>
server:
port: 8095
spring:
application:
name: admin-client
boot:
admin:
client:
url: http://127.0.0.1:8090
instance:
service-url: http://127.0.0.1:8095
management:
endpoints:
web:
exposure:
include: '*'
logging:
level:
com.dkn: debug
@RestController
@Slf4j
public class MainController {
@GetMapping("/")
public String index(){
log.debug("测试数据");
return "测试";
}
}
@SpringBootApplication
public class ClientApplication {
public static void main(String[] args) {
SpringApplication.run(ClientApplication.class,args);
}
}