pom.xml 依赖
<dependency> <groupId>com.alibaba.boot</groupId> <artifactId>nacos-config-spring-boot-starter</artifactId> <version>0.2.1</version> </dependency>
application.properties
nacos.config.server-addr=127.0.0.1:8848
启动类:
@SpringBootApplication @NacosPropertySource(dataId = "springboot2-nacos-config", autoRefreshed = true) @RestController public class DemoApplication { public static void main(String[] args) { System.out.println("12312"); new ArrayList<>(); SpringApplication.run(DemoApplication.class, args); } @NacosValue(value = "${nacos.test.propertie:123}", autoRefreshed = true) private String testProperties; @GetMapping("/test") public String test(){ return testProperties; } }
访问 127.0.0.1:8080/test
nacos控制中心
修改下值 再次访问