springboot整合nacos配置中心
发布日期:2021-06-30 11:03:36 浏览次数:2 分类:技术文章

本文共 1400 字,大约阅读时间需要 4 分钟。

1.nacos添加配置

在这里插入图片描述

在这里插入图片描述

2.项目引入依赖

com.alibaba.boot
nacos-config-spring-boot-starter
0.2.1

3.配置

spring:  application:    name: nacos_testnacos:  config:    namespace: 4f04a2dd-3c9c-49bf-b4d3-3f65f8c9762c    server-addr: 192.168.173.39:8848    file-extension: yaml    enabled: true

4.获取

package com.java4all.nacosdemo;import com.alibaba.nacos.api.config.annotation.NacosValue;import com.alibaba.nacos.spring.context.annotation.config.NacosPropertySource;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.RestController;@SpringBootApplication@RestController@NacosPropertySource(dataId = "nacos_test.yaml",groupId = "DEFAULT_GROUP",autoRefreshed = true)public class NacosdemoApplication {
@NacosValue(value = "${approval.app.appId:1762222222}",autoRefreshed = true) private String appId; @NacosValue(value = "${name:IT云清}",autoRefreshed = true) private String name; public static void main(String[] args) {
SpringApplication.run(NacosdemoApplication.class, args); } @GetMapping("test1") public String test1(String age){
System.out.println(age+" : "+appId+" : "+name); return age+" : "+appId+" : "+name; }}

转载地址:https://it4all.blog.csdn.net/article/details/111030624 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:CQRS架构实战
下一篇:一致性hash算法java实现

发表评论

最新留言

做的很好,不错不错
[***.243.131.199]2024年04月04日 10时44分54秒