菜就完事了 2020-05-21 12:35 采纳率: 50%
浏览 1000

请大神指点springCloud配置中心读取不到git的配置文件

git上的配置文件: eureka_service_config_application.yml  (仓库名 springCloud_Config   此yml文件不再任何文件夹下)

localhost-8761 已在本地 host文件配置过    本yml文件配置在eurekaservice模块 appliaction.yml启动成功   但是放到git读取就出错了

server:
  port: 8761
spring:
  application:
    name: eureka_service_config_application
  profiles: test
eureka:
  instance:
    hostname: localhost-8761  #eureka实例的主机名
  client:
    register-with-eureka: false # 不把自己注册到eureka
    fetch-registry: false  #不从eureka上来获取服务的注册信息,表示自己就是注册中心,我的职责是维护服务实例,并不需要检索服务
    service-url: 
      defaultZone: http://localhost-8761:8761/eureka/
---
server:
  port: 8762
spring:
  application:
    name: eureka_service_config_application2
  profiles: dev
eureka:
  instance:
    hostname: localhost-8762  #eureka实例的主机名
  client:
    register-with-eureka: false # 不把自己注册到eureka
    fetch-registry: false  #不从eureka上来获取服务的注册信息,表示自己就是注册中心,我的职责是维护服务实例,并不需要检索服务
    service-url: 
      defaultZone: http://localhost-8762:8762/eureka/

1.配置的config中心模块一(模块名 springCloudConfig)

server:
  port: 3344


spring:
  application:
    name: springCloudConfig
  cloud:
    config:
      server:
        git:
          uri: https://gitee.com/ykmy123/springCloud_Config.git
          #search-paths: /resources  #配置文件所在的文件位置 如果是多文件可用"," 隔开

          username: xxxxx
          password: xxxxx

并在主启动类上添加了注解 @EnableConfigServer


2.创建一个模块二(springCloudConfigClien)测试是否拉取到信息

bootstrap.yml

spring:
  cloud:
    config:
      name: eureka_service_config_application #需要从github上读取的资源名,注意没有yml后缀
      profile: test   #本访问的配置项
      label: master  #读取的分支
      uri: http://localhost:3344  #本微服务启动后会通过3344号服务,通过springCloudConfig获取github的服务

controller

@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(value="/getConfig", method= RequestMethod.GET)
    public String getConfig(){
       String str="applicationName:"+applicationName+"\t eurekaServers:"+eurekaServers+"\t port:"+port;
        System.out.println(str);
     return "applicationName:"+applicationName+"\t eurekaServers:"+eurekaServers+"\t port:"+port;
    }
}

启动
图片说明

并访问
图片说明


3.创建eurekaservice 模块三(eureka容器)

bootstrap.yml

spring:
  cloud:
    config:
      name: eureka_service_config_application #需要从github上读取的资源名,注意没有yml后缀
      profile: test   #本访问的配置项
      label: master  #读取的分支
      uri: http://localhost:3344  #本微服务启动后会通过3344号服务,通过springCloudConfig获取github的服务

application.yml

spring:
  application:
    name: eureka_service_config_application

主启动类添加 @EnableEurekaServer

启动配置中心 模块 springCloudConfig (已经把上边的模块二给关掉了)

启动eurekaservice 模块提示报错

图片说明


到这里创建了eurekaservice模块也想着拉取一下配置文件就出现一下疑问:


1.读git配置文件到项目的配置搭建思路是否有问题

2.为何模块一后 启动模块二端口是8761 可以读取到 git配置信息 (端口8761 ;而启动模块一后启动模块三 是就会报错  配置信息未读取到自动改为默认端口8080;   那模块一和模块三 配置文件都一样 按道理可以向模块二一样拉取到信息啊(个人认为可以拉取到)

3 模块二与模块三都是springboot项目  唯一不同的就是  模块二不是 eureka容器

求大神指点一下 非常感谢

  • 写回答

1条回答 默认 最新

  • 关注
    评论

报告相同问题?

悬赏问题

  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧