zoukankan      html  css  js  c++  java
  • 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;
      }
    
    }
  • 相关阅读:
    Ubuntu系统中安装Macaca过程记录
    Nightwatch——自动化测试(端对端e2e)
    junit 5 官方用户手册
    junit 5 与 testNG 使用对比
    认知体系——从“知道自己不知道”到“知道自己知道”的进化
    测试入门教程
    web UI 自动化变革龙测问世
    [黑苹果硬件] 实用黑苹果配置推荐
    windows使用vbs打开谷歌浏览器登录网页
    Note++ 的快捷
  • 原文地址:https://www.cnblogs.com/linliquan/p/13033238.html
Copyright © 2011-2022 走看看