参考官方文档(http://codecentric.github.io/spring-boot-admin/2.0.2/#getting-started),快速集成Spring Boot Admin。
1. 服务端
1.1 maven添加类库
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-server</artifactId>
<version>2.0.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
1.2 在springboot启动类添加注解
@Configuration
@EnableAutoConfiguration
@EnableAdminServer
public class SpringBootAdminApplication {
public static void main(String[] args) {
SpringApplication.run(SpringBootAdminApplication.class, args);
}
}
2. 客户端
2.1 maven添加类库
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
<version>2.0.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
2.2 springboot配置文件application.properties添加配置
spring.boot.admin.client.url: "http://localhost:8080"
management.endpoints.web.exposure.include: "*"
2.3 允许服务端访问
@Configuration
public static class SecurityPermitAllConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().anyRequest().permitAll()
.and().csrf().disable();
}
}
好了,启动服务端和客户端,服务端访问地址http://[ip]:[port],就那么简单。