# spring-boot-starter-sinsz-nacos **Repository Path**: sinszm/spring-boot-starter-sinsz-nacos ## Basic Information - **Project Name**: spring-boot-starter-sinsz-nacos - **Description**: 基于springboot扩展配置中心集成 Copyright © 2019 sinsz.com All rights reserved. https://www.sinsz.com - **Primary Language**: Java - **License**: MIT - **Default Branch**: dev - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2019-01-29 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # spring-boot-starter-sinsz-nacos **一. 介绍** 基于nacos的配置中心实现配置动态更新加载到配置变量上,从而实现配置的动态即时更新。 **二. 安装教程** **2.1. 配置依赖** ``` com.sinsz spring-boot-starter-sinsz-nacos 0.0.3 ``` **2.2. 设置类扫描范围** ``` @SpringBootApplication @NacosLoader(value = {"com.gftech.micro"}) public class BasicsApplication { public static void main(String[] args) { SpringApplication.run(BasicsApplication.class, args); } } ``` **2.3. 配置文件中添加配置** ``` #本地模式配置 sinsz: nacos: enable: true model: local address: 192.168.8.203:6578 namespace: 8a29e764-6bfc-48a7-ad42-b4df2c7cad9b timeout: 5000 config: gftech-dev: #nacos中的配置组,目前采用group与dataId的关系是一对多的形式; - videoroom #nacos中的某个配置的dataId; #阿里云ACM模式配置 sinsz: nacos: enable: true model: cloud namespace: ca180222-14d3-4764-9ae0-c87456d8dce3 timeout: 5000 acm: endpoint: acm.aliyun.com region-id: cn-shanghai open-k-m-s-filter: true access-key: 8356141asd2323a6ba7c0a5f3decde607 secret-key: QLUCE234234ErCpd6I888841m4DU= ram-role: config: gftech-dev: - videoroom ``` **三. 使用说明** **3.1. 注解方式(关键注解:@NacosAutowired,被注解的变量为配置文件对应的配置类)** ``` @RestController public class TestsController { @NacosAutowired private VideoRoomProperties properties; @OpenApi @GetMapping("/test") public String test() throws Exception { return Json.toJson(properties, JsonFormat.tidy()); } } ``` **3.2. 代码方式** ``` VideoRoomProperties prop = Cache.fetch(VideoRoomProperties.class); ``` **3.3. 特别注意事项** 3.3.1. 配置中心中配置命名规范:类的包路径 + 类的属性 = 值,示例如下: ``` VideoRoomProperties的包路径为:com.gftech.micro.properties.VideoRoomProperties VideoRoomProperties的某个属性为:regionId 最终的配置设置为:com.gftech.micro.properties.VideoRoomProperties.regionId=xxxxxx ``` 3.3.2. 属性目前支持类型为如下: ``` int Integer long Long float Float double Double boolean Boolean String ``` 3.3.3. 更多 ``` 高级功能可参照阿里云平台相关产品:应用配置管理(ACM)、RAM访问控制; 现目前,暂定支持本地化集群部署及配置获取方案,阿里云部署配置中心方案将在后期计划中实现; ``` **参与贡献** 1. Fork 本仓库 2. 新建 Feat_xxx 分支 3. 提交代码 4. 新建 Pull Request