nacos作为配置中心消费端最简单配置

pom配置


        1.8
        0.2.1
    
    
        
            com.alibaba.boot
            nacos-config-spring-boot-starter
            ${nacos-config-spring-boot.version}
        
        
            com.alibaba.boot
            nacos-config-spring-boot-actuator
            ${nacos-config-spring-boot.version}
        

        
            org.springframework.boot
            spring-boot-starter-test
            test
        
        
            org.springframework.boot
            spring-boot-starter-web
            RELEASE
            compile
        
    

启动类配置

@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;
    }
}

你可能感兴趣的:(nacos作为配置中心消费端最简单配置)