官方文档:http://codecentric.github.io/spring-boot-admin/1.5.3/#_what_is_spring_boot_admin,文档中getting-started章节,介绍了admin后台server的配置,并且spring boot和spring cloud模式下不同的配置方式,我是在cloud环境,配置如下:
<dependencies>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server</artifactId>
<version>1.5.3</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server-ui</artifactId>
<version>1.5.3</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
@Configuration
@EnableAutoConfiguration
@EnableDiscoveryClient
@EnableAdminServer
public class BootAdminApplication
spring:
application:
name: boot-admin
server:
port: 8484
eureka:
instance:
instanceId: ${spring.application.name}:${server.port}
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
healthcheck:
enabled: true
management.security.enabled: false
custom.print: hello
ok,启动boot-admin应用并会自动注册到eureka server上,启动截图如下,并访问:http://192.168.90.166:8484/#/
我发现界面可以展示应用的详细配置还包括环境变量信息,最吸引我的是还有个刷新配置的组件,咱来试试这个功能
现在就来改这个custom.print配置,经过摸索,我这里介绍两种方法热更新这个配置
- 注入Environment对象,每次都从环境对象中获取配置
- 利用@RefreshScope,但是每次在spring boot admin修改后,需要先发送refresh请求更新:curl -X POST http://192.168.90.166:8484/refresh,相当于乞丐版的spring cloud bus功能,我们一般会在git或者jekins上注册hook来自动回调这个更新
结果就不展示了,有兴趣的可以请求上面例子的endpoint去验证