整合nacos配置

This commit is contained in:
2026-02-02 15:33:19 +08:00
parent da78005ad7
commit 872be51082
4 changed files with 49 additions and 1 deletions
+6
View File
@@ -96,6 +96,12 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- Nacos 配置中心 -->
<dependency>
<groupId>com.alibaba.boot</groupId>
<artifactId>nacos-config-spring-boot-starter</artifactId>
</dependency>
</dependencies>
<build>
@@ -0,0 +1,19 @@
package top.crushtj.xiaoyishu.auth.controller;
import com.alibaba.nacos.api.config.annotation.NacosValue;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@Slf4j
@RestController
public class TestController {
@NacosValue(value = "${rate-limit.api.limit}",autoRefreshed = true)
private Integer limit;
@GetMapping("/test")
public String test() {
return "当前限流阈值为: " + limit;
}
}
@@ -82,4 +82,20 @@ jasypt:
key-obtention-iterations: 1000
string-output-type: base64
provider-name: SunJCE
iv-generator-classname: org.jasypt.iv.RandomIvGenerator
iv-generator-classname: org.jasypt.iv.RandomIvGenerator
nacos:
config: # Nacos 配置中心
access-key: # 身份验证
secret-key: # 身份验证
data-id: xiaoyishu-auth # 指定要加载的配置数据的 Data Id
group: DEFAULT_GROUP # 指定配置数据所属的组
type: yaml # 指定配置数据的格式
server-addr: http://127.0.0.1:8848/ # 指定 Nacos 配置中心的服务器地址
auto-refresh: true # 是否自动刷新配置
remote-first: true # 是否优先使用远程配置
bootstrap:
enable: true # 启动时,预热配置
rate-limit:
api:
limit: 100 # 接口限流阈值