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条回答 默认 最新

  • 关注
    评论

报告相同问题?

悬赏问题

  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?
  • ¥15 电磁场的matlab仿真
  • ¥15 mars2d在vue3中的引入问题
  • ¥50 h5唤醒支付宝并跳转至向小荷包转账界面