pom配置
<properties>
<java.version>1.8</java.version>
<nacos-config-spring-boot.version>0.2.1</nacos-config-spring-boot.version>
</properties>
<dependencies>
<dependency>
<groupId>com.alibaba.boot</groupId>
<artifactId>nacos-config-spring-boot-starter</artifactId>
<version>${nacos-config-spring-boot.version}</version>
</dependency>
<dependency>
<groupId>com.alibaba.boot</groupId>
<artifactId>nacos-config-spring-boot-actuator</artifactId>
<version>${nacos-config-spring-boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>RELEASE</version>
<scope>compile</scope>
</dependency>
</dependencies>
启动类配置
@SpringBootApplication
@NacosPropertySource(dataId = "demo",autoRefreshed = true)
public class NacosConfigApplication {
public static void main(String[] args) {
SpringApplication.run(NacosConfigApplication.class, args);
}
}
controller配置
@RestController
@RequestMapping("config")
public class ConfigController {
@NacosValue(value = "${testFlag}",autoRefreshed = true)
private boolean testFlag;
@RequestMapping(value = "/flag",method = GET)
public boolean fetchFlag() {
return testFlag;
}
}
网友评论