您的位置:首页 > 编程语言 > Java开发

spring cloud nacos 二 spring-cloud-alibaba-nacos-config 的使用

2019-07-02 12:11 399 查看
版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。 本文链接:https://blog.csdn.net/WithCYwind/article/details/94436817

1.pom.xml

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba-nacos-config</artifactId>
<version>0.9.0.RELEASE</version>
</dependency>

2.在nacos 管理中心 的配置列表 添加配置

3.在服务提供者 创建controller

package com.sunup.practice.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RefreshScope
public class ConfigController {
@Value("${username:lime}")
private String username;

@GetMapping("/username")
public String get(){
return username;
}
}

4.重启服务提供者
访问http://localhost:8761/username

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: