2微服务 之 nacos 集成 Spring Boot Admin

配置

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
在这里插入图片描述
在这里插入图片描述

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
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值