Nacos教程_4 配置讲解

妖狐艹你老母 2023-01-06 11:45 164阅读 0赞

教程原稿 https://gitee.com/fakerlove/joker-nacos

文章目录

    1. 配置讲解
    • 4.1 dataid 配置讲解
    • 4.2 实现自动装填

4. 配置讲解

4.1 dataid 配置讲解

在 Nacos Spring Cloud 中,dataId 的完整格式如下:

  1. ${prefix}-${spring.profiles.active}.${file-extension}
  • prefix 默认为 spring.application.name 的值,也可以通过配置项 spring.cloud.nacos.config.prefix来配置。
  • spring.profiles.active 即为当前环境对应的 profile,详情可以参考 Spring Boot文档。 注意:当 spring.profiles.active 为空时,对应的连接符 - 也将不存在,dataId 的拼接格式变成 ${prefix}.${file-extension}
  • file-exetension 为配置内容的数据格式,可以通过配置项 spring.cloud.nacos.config.file-extension 来配置。目前只支持 propertiesyaml 类型。

4.2 实现自动装填

  1. package cn.com.geostar.datasource;
  2. import org.springframework.boot.context.properties.ConfigurationProperties;
  3. import org.springframework.cloud.context.config.annotation.RefreshScope;
  4. import org.springframework.stereotype.Component;
  5. /**
  6. * @author xiawei
  7. * @date 2020/8/10 11:33
  8. */
  9. @Component
  10. @RefreshScope
  11. @ConfigurationProperties(prefix = "jedispool.config")
  12. public class JedisPoolConfigure {
  13. private boolean enable;
  14. private String host;
  15. private Integer port;
  16. private String password;
  17. private Integer timeOut;
  18. private Integer maxIdle;
  19. private Integer maxWaitMillis;
  20. private Integer maxTotal;
  21. }

发表评论

表情:
评论列表 (有 0 条评论,164人围观)

还没有评论,来说两句吧...

相关阅读

    相关 4-SpringCloudAlibaba整合Nacos配置中心

    Nacos可以帮助应用程序动态地管理和配置各种配置信息,例如应用程序的配置参数、数据库连接信息、日志级别、特性开关等。通过使用Nacos配置中心,可以将这些配置信息集中管理,而