nacos配置中心笔记

/ 默认分类 / 0 条评论 / 799浏览

nacos配置中心笔记

  1. 笔记一
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
@NacosPropertySource(dataId = "springboot2-nacos-config", autoRefreshed = true)
@RestController
public class Springboot2NacosConfigApplication {

    public static void main(String[] args) {
        SpringApplication.run(Springboot2NacosConfigApplication.class, args);
    }

    @NacosValue(value = "${nacos.test.propertie:123}", autoRefreshed = true)
    private String testProperties;

    @GetMapping("/test")
    public String test(){
        return testProperties;
    }
}
  1. 笔记二,单独按照类动态刷新

  2. 笔记三

nacos配置中心编写配置

cases:
  ftpPath: "" #http://:8080/
  prefix: "" #"TYYW."
  dbLinks: "" #"@tyywsc.net"
  isTiming: 1 #是否开启定时任务(1:开启;0:不开启)

添加依赖

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-configuration-processor</artifactId>
    <optional>true</optional>
</dependency>

配置信息编写

import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;


@Getter
@Setter
@Component
@ConfigurationProperties(prefix = "cases")
public class RefreshConfig {

    /**
     * 是否开启定时任务
     */
    private Integer  isTiming;

    /**
     * oracle表用户
     */
    private String  prefix;

    /**
     * oracle令牌
     */
    private String  dbLinks;
}