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

}
原文地址:https://www.cnblogs.com/linliquan/p/13033238.html