springcloud config配置采坑 Could not resolve placeholder 'from' in value "${from}報錯,巨坑!


最經在搭建springcloud config配置中心的時候,發現一切配置都配置正確了,但是microservice-config-client客戶端一直啟動報錯:org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'configClientController': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'from' in value "${from}"
如下:

 

 

 

 

找了兩天都沒發現錯了哪里,結果發現,是github上的倉庫里的microservice-dev.yml配置文件名有問題,識別不了yml格式的,設置成properties類型就可以了,巨坑!

 

 

 

 修改好后如下:

 

 

然后訪問 http://localhost:8081/from 就可以了

 

 



yml配置:
microservice-config-server服務端配置
server:
  port: 8080
spring:
  application:
    name: microservice-config-server
  cloud:
    config:
      server:
        git:
          # Git倉庫地址
          uri: https://github.com/Linliquan/spring-cloud-config-repo.git
          search-paths: config-repo
          # Git倉庫賬號
          username: Linliquan
          # Git倉庫密碼
          password: xxxxx
eureka:
  client:
    service-url:
      defaultZone: http://localhost:8761/eureka/

microservice-config-client客戶端配置
spring:
  application:
    name: microservice-client    # 對應config server所獲取的配置文件的{application}
  cloud:
    config:
      name: microservice
      uri: http://localhost:8080/
      profile: dev            # profile對應config server所獲取的配置文件中的{profile} 
      label: master           # 指定Git倉庫的分支,對應config server所獲取的配置文件的{label}

microservice-config-client客戶端restful API調用:
@RestController
public class ConfigClientController {

  @Value("${from}")
  private String from;

  @GetMapping("/from")
  public String hello() {
    return this.from;
  }

}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM