Spring Cloud Config Client注意问题

1.config-client启动报无法注入“from”的value
2.默认连接端口8888
Could not locate PropertySource: I/O error on GET request for “http://localhost:8888/config-client/dev/master”

根本原因是你使用了application.properties
要更改为bootstrap.properties,它优先于前者加载,父配置文件,为前者提供需要的参数值


    @RefreshScope
    @RestController
    public class TestController {
        //必须用brootstrap命名,否则报错
         @Value("${from}")
        private String from;
    
        @RequestMapping("/from")
        public String from() {
            return this.from;
        }
        @Autowired
        private Environment env;
        @RequestMapping("/from2")
        public String from2() {
            return env.getProperty("from", "undefined");
        }
    }

bootstrap.properties文件:


    spring.application.name=didispace
    spring.cloud.config.profile=dev
    spring.cloud.config.label=master
    spring.cloud.config.uri=http://localhost:7001/
    server.port=7002

你可能感兴趣的:(springcloud)