为什么属性映射到YAML时返回空值?

huangapple go评论69阅读模式
英文:

why the properties map to yaml return null

问题

I have a java properties config look like this:

spring.cloud.gateway.routes[9].id = dict-auth
spring.cloud.gateway.routes[9].order = 0
spring.cloud.gateway.routes[9].predicates[0] = Path=/dict/user/plugin/login
spring.cloud.gateway.routes[9].uri = http://10.98.176.2:11014
spring.cloud.gateway.routes[10].filters[0] = RewritePath=/dict/auth/access_token/refresh, /post/auth/access_token/refresh
spring.cloud.gateway.routes[10].id = dict-access-token-refresh
spring.cloud.gateway.routes[10].order = 1
spring.cloud.gateway.routes[10].predicates[0] = Path=/dict/auth/access_token/refresh
spring.cloud.gateway.routes[10].uri = http://10.98.176.2:11014
spring.cloud.gateway.routes[11].filters[0] = RewritePath=/dict/auth/refresh_token/refresh, /post/auth/refresh_token/refresh
spring.cloud.gateway.routes[11].id = dict-refresh-token-refresh
spring.cloud.gateway.routes[11].order = 2
spring.cloud.gateway.routes[11].predicates[0] = Path=/dict/auth/refresh_token/refresh
spring.cloud.gateway.routes[11].uri = http://10.98.176.2:11014

When I am using online tool to map to yaml, it shows a result like this:

spring:
cloud:
gateway:
routes:
- null
- null
- null
- null
- null
- null
- null
- null
- null
- id: dict-auth
order: 0
predicates:
- Path=/dict/user/plugin/login
uri: http://10.98.176.2:11014
- null
- filters:
- RewritePath=/dict/auth/access_token/refresh, /post/auth/access_token/refresh
id: dict-access-token-refresh
order: 1
predicates:
- Path=/dict/auth/access_token/refresh
uri: http://10.98.176.2:11014
- filters:
- RewritePath=/dict/auth/refresh_token/refresh, /post/auth/refresh_token/refresh
id: dict-refresh-token-refresh
order: 2
predicates:
- Path=/dict/auth/refresh_token/refresh
uri: http://10.98.176.2:11014

Am I missing something? What should I do to fix this problem? BTW, this is the full config of the route:

spring.cloud.gateway.routes[0].filters[0].name = JwtAuthentication
spring.cloud.gateway.routes[0].id = time-capsule-service
spring.cloud.gateway.routes[0].order = 2
spring.cloud.gateway.routes[0].predicates[0] = Path=/tik/**
spring.cloud.gateway.routes[0].uri = http://10.111.149.10:11015
spring.cloud.gateway.routes1.filters[0].name = JwtAuthentication
spring.cloud.gateway.routes1.id = fortune-service
spring.cloud.gateway.routes1.order = 2
spring.cloud.gateway.routes1.predicates[0] = Path=/fortune/**
spring.cloud.gateway.routes1.uri = http://10.96.112.198:11015
spring.cloud.gateway.routes[2].filters[0].name = JwtAuthentication
spring.cloud.gateway.routes[2].id = dolphin-music-service
spring.cloud.gateway.routes[2].predicates[0] = Path=/music/**
spring.cloud.gateway.routes[2].uri = http://10.107.64.246:11014
spring.cloud.gateway.routes[3].filters[0].name = JwtAuthentication
spring.cloud.gateway.routes[3].id = dolphin-post-service
spring.cloud.gateway.routes[3].predicates[0] = Path=/post/**
spring.cloud.gateway.routes[3].uri = http://10.98.176.2:11014
spring.cloud.gateway.routes[4].filters[0].name = JwtAuthentication
spring.cloud.gateway.routes[4].id = dolphin-manage-service
spring.cloud.gateway.routes[4].order = 2
spring.cloud.gateway.routes[4].predicates[0] = Path=/manage/**
spring.cloud.gateway.routes[4].uri = http://10.106.240.158:11015
spring.cloud.gateway.routes[5].id = dolphin-login-service
spring.cloud.gateway.routes[5].order = 0
spring.cloud.gateway.routes[5].predicates[0] = Path=/manage/admin/user/login,/fortune/user/login,/fortune/user/sms,/fortune/user/reg/verify,/fortune/user/guest/login,/dict/user/login
spring.cloud.gateway.routes[5].uri = http://10.98.176.2:11014
spring.cloud.gateway.routes[6].id = dolphin-logout-service
spring.cloud.gateway.routes[6].order = 0
spring.cloud.gateway.routes[6].predicates[0] = Path=/manage/admin/user/logout
spring.cloud.gateway.routes[6].uri = http://10.98.176.2:11014
spring.cloud.gateway.routes[7].id = dolphin-login-current-admin-user
spring.cloud.gateway.routes[7].order = 0
spring.cloud.gateway.routes[7].predicates[0] = Path=/manage/admin/user/current-user
spring.cloud.gateway.routes[7].uri = http://10.98.176.2:11014
spring.cloud.gateway.routes[8].filters[0].name = JwtAuthentication
spring.cloud.gateway.routes[8].id = dolphin-dict-service
spring.cloud.gateway.routes[8].order = 3
spring.cloud.gateway.routes[8].predicates[0] = Path=/dict/**
spring.cloud.gateway.routes[8].uri = http://10.97.100.34:11014
spring.cloud.gateway.routes[9].id = dict-auth
spring.cloud.gateway.routes[9].order = 0
spring.cloud.gateway.routes[9].predicates[0] = Path=/dict/user/plugin/login
spring.cloud.gateway.routes[9].uri = http:

英文:

I have a java properties config look like this:

spring.cloud.gateway.routes[9].id = dict-auth
spring.cloud.gateway.routes[9].order = 0
spring.cloud.gateway.routes[9].predicates[0] = Path=/dict/user/plugin/login
spring.cloud.gateway.routes[9].uri = http://10.98.176.2:11014
spring.cloud.gateway.routes[10].filters[0] = RewritePath=/dict/auth/access_token/refresh, /post/auth/access_token/refresh
spring.cloud.gateway.routes[10].id = dict-access-token-refresh
spring.cloud.gateway.routes[10].order = 1
spring.cloud.gateway.routes[10].predicates[0] = Path=/dict/auth/access_token/refresh
spring.cloud.gateway.routes[10].uri = http://10.98.176.2:11014
spring.cloud.gateway.routes[11].filters[0] = RewritePath=/dict/auth/refresh_token/refresh, /post/auth/refresh_token/refresh
spring.cloud.gateway.routes[11].id = dict-refresh-token-refresh
spring.cloud.gateway.routes[11].order = 2
spring.cloud.gateway.routes[11].predicates[0] = Path=/dict/auth/refresh_token/refresh
spring.cloud.gateway.routes[11].uri = http://10.98.176.2:11014

when I am using online tool map to yaml, shows result like this:

spring:
  cloud:
    gateway:
      routes:
      - null
      - null
      - null
      - null
      - null
      - null
      - null
      - null
      - null
      - id: dict-auth
        order: 0
        predicates:
        - Path=/dict/user/plugin/login
        uri: http://10.98.176.2:11014
      - null
      - filters:
        - RewritePath=/dict/auth/access_token/refresh, /post/auth/access_token/refresh
        id: dict-access-token-refresh
        order: 1
        predicates:
        - Path=/dict/auth/access_token/refresh
        uri: http://10.98.176.2:11014
      - filters:
        - RewritePath=/dict/auth/refresh_token/refresh, /post/auth/refresh_token/refresh
        id: dict-refresh-token-refresh
        order: 2
        predicates:
        - Path=/dict/auth/refresh_token/refresh
        uri: http://10.98.176.2:11014

Am I missing something? what should I do to fixed this problem? BTW, this is the full config of route looks like:

spring.cloud.gateway.routes[0].filters[0].name = JwtAuthentication
spring.cloud.gateway.routes[0].id = time-capsule-service
spring.cloud.gateway.routes[0].order = 2
spring.cloud.gateway.routes[0].predicates[0] = Path=/tik/**
spring.cloud.gateway.routes[0].uri = http://10.111.149.10:11015
spring.cloud.gateway.routes[1].filters[0].name = JwtAuthentication
spring.cloud.gateway.routes[1].id = fortune-service
spring.cloud.gateway.routes[1].order = 2
spring.cloud.gateway.routes[1].predicates[0] = Path=/fortune/**
spring.cloud.gateway.routes[1].uri = http://10.96.112.198:11015
spring.cloud.gateway.routes[2].filters[0].name = JwtAuthentication
spring.cloud.gateway.routes[2].id = dolphin-music-service
spring.cloud.gateway.routes[2].predicates[0] = Path=/music/**
spring.cloud.gateway.routes[2].uri = http://10.107.64.246:11014
spring.cloud.gateway.routes[3].filters[0].name = JwtAuthentication
spring.cloud.gateway.routes[3].id = dolphin-post-service
spring.cloud.gateway.routes[3].predicates[0] = Path=/post/**
spring.cloud.gateway.routes[3].uri = http://10.98.176.2:11014
spring.cloud.gateway.routes[4].filters[0].name = JwtAuthentication
spring.cloud.gateway.routes[4].id = dolphin-manage-service
spring.cloud.gateway.routes[4].order = 2
spring.cloud.gateway.routes[4].predicates[0] = Path=/manage/**
spring.cloud.gateway.routes[4].uri = http://10.106.240.158:11015
spring.cloud.gateway.routes[5].id = dolphin-login-service
spring.cloud.gateway.routes[5].order = 0
spring.cloud.gateway.routes[5].predicates[0] = Path=/manage/admin/user/login,/fortune/user/login,/fortune/user/sms,/fortune/user/reg/verify,/fortune/user/guest/login,/dict/user/login
spring.cloud.gateway.routes[5].uri = http://10.98.176.2:11014
spring.cloud.gateway.routes[6].id = dolphin-logout-service
spring.cloud.gateway.routes[6].order = 0
spring.cloud.gateway.routes[6].predicates[0] = Path=/manage/admin/user/logout
spring.cloud.gateway.routes[6].uri = http://10.98.176.2:11014
spring.cloud.gateway.routes[7].id = dolphin-login-current-admin-user
spring.cloud.gateway.routes[7].order = 0
spring.cloud.gateway.routes[7].predicates[0] = Path=/manage/admin/user/current-user
spring.cloud.gateway.routes[7].uri = http://10.98.176.2:11014
spring.cloud.gateway.routes[8].filters[0].name = JwtAuthentication
spring.cloud.gateway.routes[8].id = dolphin-dict-service
spring.cloud.gateway.routes[8].order = 3
spring.cloud.gateway.routes[8].predicates[0] = Path=/dict/**
spring.cloud.gateway.routes[8].uri = http://10.97.100.34:11014
spring.cloud.gateway.routes[9].id = dict-auth
spring.cloud.gateway.routes[9].order = 0
spring.cloud.gateway.routes[9].predicates[0] = Path=/dict/user/plugin/login
spring.cloud.gateway.routes[9].uri = http://10.98.176.2:11014
spring.cloud.gateway.routes[10].filters[0] = RewritePath=/dict/auth/access_token/refresh, /post/auth/access_token/refresh
spring.cloud.gateway.routes[10].id = dict-access-token-refresh
spring.cloud.gateway.routes[10].order = 1
spring.cloud.gateway.routes[10].predicates[0] = Path=/dict/auth/access_token/refresh
spring.cloud.gateway.routes[10].uri = http://10.98.176.2:11014
spring.cloud.gateway.routes[11].filters[0] = RewritePath=/dict/auth/refresh_token/refresh, /post/auth/refresh_token/refresh
spring.cloud.gateway.routes[11].id = dict-refresh-token-refresh
spring.cloud.gateway.routes[11].order = 2
spring.cloud.gateway.routes[11].predicates[0] = Path=/dict/auth/refresh_token/refresh
spring.cloud.gateway.routes[11].uri = http://10.98.176.2:11014

答案1

得分: 1

因为 spring.cloud.gateway.routes 是一个路由对象列表,方括号内的数字是每个路由的索引位置(从0开始)。目前,您没有为 spring.cloud.gateway.routes[0]spring.cloud.gateway.routes[8] 指定任何内容,所以 yml 中的前9项都是空的。

要修复它,您需要将索引重命名为:

spring.cloud.gateway.routes[0].id = dict-auth
spring.cloud.gateway.routes[0].order = 0
spring.cloud.gateway.routes[0].predicates[0] = Path=/dict/user/plugin/login
spring.cloud.gateway.routes[0].uri = http://10.98.176.2:11014
spring.cloud.gateway.routes[1].filters[0] = RewritePath=/dict/auth/access_token/refresh, /post/auth/access_token/refresh
spring.cloud.gateway.routes[1].id = dict-access-token-refresh
spring.cloud.gateway.routes[1].order = 1
spring.cloud.gateway.routes[1].predicates[0] = Path=/dict/auth/access_token/refresh
spring.cloud.gateway.routes[1].uri = http://10.98.176.2:11014
spring.cloud.gateway.routes[2].filters[0] = RewritePath=/dict/auth/refresh_token/refresh, /post/auth/refresh_token/refresh
spring.cloud.gateway.routes[2].id = dict-refresh-token-refresh
spring.cloud.gateway.routes[2].order = 2
spring.cloud.gateway.routes[2].predicates[0] = Path=/dict/auth/refresh_token/refresh
spring.cloud.gateway.routes[2].uri = http://10.98.176.2:11014

英文:

Because spring.cloud.gateway.routes is a list of route object , and the number inside the bracket is the index position (0-based) of each route. Now you do not specify anything for spring.cloud.gateway.routes[0] up to spring.cloud.gateway.routes[8] , so the first 9 items in the yml is null.

To fix it, you have to rename the index to :

spring.cloud.gateway.routes[0].id = dict-auth
spring.cloud.gateway.routes[0].order = 0
spring.cloud.gateway.routes[0].predicates[0] = Path=/dict/user/plugin/login
spring.cloud.gateway.routes[0].uri = http://10.98.176.2:11014
spring.cloud.gateway.routes[1].filters[0] = RewritePath=/dict/auth/access_token/refresh, /post/auth/access_token/refresh
spring.cloud.gateway.routes[1].id = dict-access-token-refresh
spring.cloud.gateway.routes[1].order = 1
spring.cloud.gateway.routes[1].predicates[0] = Path=/dict/auth/access_token/refresh
spring.cloud.gateway.routes[1].uri = http://10.98.176.2:11014
spring.cloud.gateway.routes[2].filters[0] = RewritePath=/dict/auth/refresh_token/refresh, /post/auth/refresh_token/refresh
spring.cloud.gateway.routes[2].id = dict-refresh-token-refresh
spring.cloud.gateway.routes[2].order = 2
spring.cloud.gateway.routes[2].predicates[0] = Path=/dict/auth/refresh_token/refresh
spring.cloud.gateway.routes[2].uri = http://10.98.176.2:11014

huangapple
  • 本文由 发表于 2023年3月3日 21:47:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/75627889.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定