配置
Spring Boot Admin server 端配置 依赖
implementation 'de.codecentric:spring-boot-admin-starter-server'
implementation('com.alibaba.cloud:spring-cloud-starter-alibaba-nacos-config')
implementation('com.alibaba.cloud:spring-cloud-starter-alibaba-nacos-discovery')
配置 注册中心 与 配置中心 , 以及公共配置 common.yml
spring:
profiles: dev
cloud:
nacos:
discovery:
server-addr: 127.0.0.1:8848
config:
server-addr: 127.0.0.1:8848
file-extension: yaml
shared-dataids: common.yml #公共配置文件
nacos web 设置 common.yml
![](https://img.laitimes.com/img/9ZDMuAjOiMmIsIjOiQnIsIiclRnblN2XjlGcjAzNfRHLGZkRGZkRfJ3bs92YsYTMfVmepNHL9klaNNTQq10dBRVT3V1MMBjVtJWd0ckW65UbM5WOHJWa5kHT20ESjBjUIF2X0hXZ0xCMx81dvRWYoNHLrdEZwZ1Rh5WNXp1bwNjW1ZUba9VZwlHdssmch1mclRXY39CXldWYtlWPzNXZj9mcw1ycz9WL49zZuBnL5YzM5UjMwMjMwIDOwAjMwIzLc52YucWbp5GZzNmLn9Gbi1yZtl2Lc9CX6MHc0RHaiojIsJye.png)
management:
endpoints:
web:
exposure:
include: '*'
endpoint:
health:
show-details: always
配置 spring boot 启动项 启动
@SpringBootApplication
@EnableAdminServer
public class adminApplication {
public static void main(String[] args) {
SpringApplication.run(adminApplication.class, args);
}
}
启动一个需要被 Spring Boot Admin 管理的 项目
依赖如下
implementation 'de.codecentric:spring-boot-admin-starter-client'
implementation('com.alibaba.cloud:spring-cloud-starter-alibaba-nacos-config')
implementation('com.alibaba.cloud:spring-cloud-starter-alibaba-nacos-discovery')
打开 Spring Boot Admin 查看结果
注意事项
1其他共同依赖放在父 依赖里面统一管理了
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
mavenBom "de.codecentric:spring-boot-admin-dependencies:${springBootAdminVersion}"
mavenBom "com.alibaba.cloud:spring-cloud-alibaba-dependencies:${springCloudAlibabaVersion}"
}
}
dependencies {
testImplementation('org.springframework.boot:spring-boot-starter-test')
implementation('org.springframework.boot:spring-boot-starter-web')
implementation('org.springframework.boot:spring-boot-starter-actuator')
}
2 如果要在 Spring Boot Admin 查看 日志 需要 在 yaml 文件 里面配置日志路径
logging:
file:
path: /logs/${spring.application.name} # 在logback-spring.xml中引用这个值 作为 LOG_HOME
name: ${logging.file.path}/console.log # 在logback-spring.xml中引用这个值作为 LOG_FILE