1、项目案例 @NacosValue(value = "${order.url}", autoRefreshed = true) private String orderUrl; 2、用法介绍 在S
@NacosValue(value = "${order.url}", autoRefreshed = true) private String orderUrl;
@NacosValue的使用
引入依赖:
>>com.alibaba.boot >>nacos-config-spring-boot-starter >ion>0.2.12> >
配置文件增加配置:nacos: config: server-addr: 127.0.0.1:8848 //配置nacos配置中心的服务地址 bootstrap: enable: true log: enable: true data-id: order-service type: yaml auto-refresh: true # 开启自动刷新
@NacosValue的例子:
package com.morris.order.controller;import com.alibaba.nacos.api.config.annotation.NacosValue;import org.springframework.WEB.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;@RestController@RequestMapping("order")public class NacosValueController { @NacosValue(value = "${user.age}", autoRefreshed = true) private Integer age2; @GetMapping("age2") public Integer getAge2() { return age2; }}
可以发现我们已经成功去到了配置中心里面的值,到此自动刷新配置已完成。
来源地址:https://blog.csdn.net/zouyang920/article/details/129873871
--结束END--
本文标题: @NacosValue注解的用法
本文链接: https://www.lsjlt.com/news/423213.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-04-01
2024-04-03
2024-04-03
2024-01-21
2024-01-21
2024-01-21
2024-01-21
2023-12-23
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0