首页 > 解决方案 > spring boot中的属性文件读取错误

问题描述

下面是我在 Spring Boot 应用程序中的 yml 文件

stack:
  apiContext: data-service
  domainOwner: trata
  domainContext: Madata-service
  #cluster:
   # servicePort: 12000
    #gossipPort: 13000
    #seedName: seed-service
   # seeds:
  #    - localhost:14000
  cluster:
    servicePort: 21000
    gossipPort: 15000
#    seedName: seed-service
    seeds:
      - localhost:13000
  providers:
    com.cloudimpl.out.collection.CollectionProvider:
      - name: MemCollection
        impl: com.cloudimpl.outstack.collection.MemCollectionProvider
        status: active

      - name: com.cloudimpl.outstack.collection.CollectionProvider
        impl: com.cloudimpl.outstack.collection.AwsCollectionProvider
        #        status: active
        configs:
          endpoint: http://localhost:1234
          leaderTable: LeaderTable
    com.cloudimpl.outstack.runtime.EventRepositoryFactory:
      - name: MemRepositoryFactory
        impl: com.cloudimpl.outstack.runtime.repo.MemEventRepositoryFactory


      - name: PostgresRepositoryFactory
        impl: com.cloudimpl.outstack.spring.repo.PostgresRepositoryFactory
        status: active
        configs:
          jdbcUrl: jdbc:postgresql://localhost:5432/test
          username: postgres
          password: QazWsx@1234
          defaultTable: masterdataService
          #UserTable: userTable
server:
  port: 9096
spring:
  main:
    web-application-type: reactive

低于值访问是工作文件

@Value("${outstack.domainOwner}")
private String abc;

但是当我尝试以下面的方式访问它时会出错。

@Value("${outstack.providers.com.cloudimpl.outstack.runtime.EventRepositoryFactory.name}")
private String abc;

我检查了它仅在添加“com.cloudimpl.outstack.runtime.EventRepositoryFactory”这部分时才给出错误。

我该如何解决这个问题?

标签: javaspringspring-bootyaml

解决方案


它不起作用。您在“outstack.providers.com.cloudimpl.outstack.runtime.EventRepositoryFactory”下有值列表。这意味着您可以像这样添加变量:

@Value("${outstack.providers.com.cloudimpl.outstack.runtime.EventRepositoryFactory}")
private List<ParamWrapper> abc;

class ParamWrapper {

private String name;
private String impl;

....
getters and setters
}

然后检查此列表中的参数。


推荐阅读