关于bootstrap.properties读取不到nacos配置中心的解决方案

pom配置:

springboot:2.2.1.RELEASE.

springcloud:Hoxton.SR9.

出现错误:

bootstrap.properties读取不到nacos配置中心的内容,@value注入不了数据.

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'couponController': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'coupon.user.name' in value "${coupon.user.name}"

解决步骤:

        首先添加了bootstrap的相关依赖,但还是不起作用.

        <!--解决spring boot不加载bootstrap.properties文件的问题-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-bootstrap</artifactId>
            <version>3.0.1</version>
        </dependency>

        其次查看alibaba版本文档,链接如下:

  1. 版本说明 · alibaba/spring-cloud-alibaba Wiki · GitHub

 

         发现springboot版本和springcloud版本对应不上,后把Hoxton.SR9改成了Hoxton.RELEASE,再次启动就可以读取配置中心的文件了