首页 > 解决方案 > 微服务的 yml 文件中的解析错误

问题描述

18:01:39.008 [main] 错误 org.springframework.boot.SpringApplication - 应用程序运行失败 org.yaml.snakeyaml.scanner.ScannerException:在“阅读器”第 16 行第 16 列中不允许映射值:uri:lb ://用户服务

`

server:
  port: 9190


spring:
  application:
    name: API-Gateway
  cloud:
    gateway:
      routes:
        - id: user-service
          uri: lb://DEPT-SERVICE
          predicates:
            - path=/user/**
        - id: dept-service
            uri: lb://USER-SERVICE
            predicates:
              - path=/departments/**
eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka
    instance:
    preferIpAddress: true

`

标签: spring-bootmicroservicesnetflix-eureka

解决方案


您的 yaml 无效。检查此验证器作为示例。

请注意第 16 行和下一行uripredicates和 与path之前不在同一列上。

有效的 yaml 是:

server:
  port: 9190


spring:
  application:
    name: API-Gateway
  cloud:
    gateway:
      routes:
        - id: user-service
          uri: lb://DEPT-SERVICE
          predicates:
            - path=/user/**
        - id: dept-service
          uri: lb://USER-SERVICE
          predicates:
            - path=/departments/**
eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka
    instance:
    preferIpAddress: true

推荐阅读