欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

nacos中的配置使用@Value注解獲取不到值的原因及解決方案

 更新時(shí)間:2023年03月30日 09:31:41   作者:渝小白  
這篇文章主要介紹了nacos中的配置使用@Value注解獲取不到值的原因分析,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

可能導(dǎo)致問題的原因:
1.nacos中的配置文件名不規(guī)范,官網(wǎng)有命名規(guī)則:“前綴”-“激活的環(huán)境配置”."文件后綴”
例如:nacosdemo-dev.yaml。

在這里插入圖片描述

2.配置文件的后綴名寫錯(cuò)了,后綴名有兩種,yamlproperties,不能寫成yml,項(xiàng)目中的配置文件中也要檢查后綴名是否一致,如果用yaml類型的配置,需要在bootstrap.properties文件中添加這行配置來指定類型**“spring.cloud.nacos.config.file-extension=yaml**”
官網(wǎng)地址https://github.com/alibaba/spring-cloud-alibaba/wiki/Nacos-config
3.如果要使用nacos做為外部配置,就需要將連接nacos的配置寫在bootstrap.properties或者bootstrap.yaml文件中,application.properties文件可以刪除掉,或者application.properties中只配置server.port,注意:spring.application.name要和nacos中的配置文件名一致,不需要加后綴,如果是nacos中是yaml格式的配置加上spring.cloud.nacos.config.file-extension=yaml,不加默認(rèn)是properties格式。

在這里插入圖片描述

在這里插入圖片描述

4.可能識(shí)別不到bootstrap.properties配置文件,加入以下依賴:

		<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-bootstrap</artifactId>
        </dependency>

完整依賴如下:

 <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-dependencies</artifactId>
        <version>2021.0.3</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
      <dependency>
        <groupId>com.alibaba.cloud</groupId>
        <artifactId>spring-cloud-alibaba-dependencies</artifactId>
        <version>2.2.9.RELEASE</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>
  
   <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
        </dependency>
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-bootstrap</artifactId>
        </dependency>
    </dependencies>

到此這篇關(guān)于nacos中的配置使用@Value注解獲取不到值的文章就介紹到這了,更多相關(guān)@Value注解獲取不到值內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論