lb_hard 2019-09-19 11:09 采纳率: 0%
浏览 863

springcloud config client端通过访问server端远程获取git上面的yml中的内容,获取失败,求各路大神求解

spring config client端bootstrap.yml

  cloud:
    config:
      name: microservicecloud-config-client #需要从git上读取的资源名称,注意没有yml后缀名
      profile: dev  #本次访问的配置项
      label: master
      uri: http://config-3344.com:3344  #本微服务启动后先去找3344号服务,通过SpringCloudConfig获取git的服务地址

类ConfigClientRest

@RestController
public class ConfigClientRest {

    @Value("${spring.application.name}")
    private String applicationName;

    @Value("${eureka.client.service-url.defaultZone}")
    private String eurekaServers;

    @Value("${server.port}")
    private String port;

    @RequestMapping("/config")
    public String getConfig(){
        String str = "applicationName: " + applicationName
                + "\t eurekaServers: " + eurekaServers
                + "\t port: " + port;
        System.out.println("*****str: " + str);
        return "applicationName: " + applicationName
                + "\t eurekaServers: " + eurekaServers
                + "\t port: " + port;
    }
}

码云上面microservicecloud-config-client.yml

spring: 
    profiles: 
        active: 
        - dev
---
server: 
    port: 8201
spring: 
    profiles: dev
    application: 
        name: microservicecloud-config-client
eureka: 
    client: 
        service-url: 
            defaultZone: http://eureka-dev.com:7001/eureka/
---
server: 
    port: 8202
spring: 
    profiles: test
    application:  
        name: microservicecloud-config-client
eureka: 
    client: 
        service-url: 
            defaultZone: http://eureka-test.com:7001/eureka/

springcloud config server端application.xml

server:
  port: 3344

spring:
  application:
    name: microservicecloud-config
  cloud:
   config:
     server:
       git:
         uri: git@gitee.com:lb20162501306/mricoservicecloud-config.git  #码云上git仓库地址

报错

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

  • 写回答

1条回答 默认 最新

  • 关注
    评论

报告相同问题?

悬赏问题

  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献