springcloud-nacos配置中心

1.依赖

        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
        </dependency>

 2.配置文件

server.port=9001
spring.application.name=userservices
spring.cloud.nacos.server-addr=127.0.0.1:8848
spring.cloud.nacos.discovery.server-addr=${spring.cloud.nacos.server-addr}

spring.cloud.nacos.config.namespace=fa1dc366-6e3f-46d4-bd67-18ae4c6ad2d7
spring.cloud.nacos.config.group=USER
spring.profiles.active=prod
spring.cloud.nacos.config.file-extension=properties

 3.Controller

@RestController
@RefreshScope
public class ConfigController {
    //注入配置
    @Value("${user.name}")
    private String username;

    @RequestMapping("/getConfig")
    public String getConfig(){
        return username;
    }
}

 4.自动刷新

@RefreshScope
posted @ 2020-09-02 20:03  陶海军  阅读(257)  评论(0编辑  收藏  举报