java - 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”这部分时才给出错误。
我该如何解决这个问题?
解决方案
它不起作用。您在“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
}
然后检查此列表中的参数。
推荐阅读
- javascript - 无法读取数组中未定义的属性“获取”
- python - 在雪花 Web UI 中工作但通过 python sqlalchemy 连接器不一致的查询
- android - react-native run-android 失败 MacOS
- java - 在 java 中的 MongoDB 字段级编辑中无法识别为参考
- sql - SQL 语句从连接返回匹配记录,从连接返回空记录
- javascript - JavaScript FileReader 如何读取不同的编码文件
- firebase - 如何注册用户并在注册页面中自动链接一些用户特定数据与颤振?
- amazon-web-services - AWS ECS 中的服务发现
- matlab - Simulink - 如何配置范围的外观
- mulesoft - 如何在 Mule4 中使用本地主机测试 Https 侦听器