Java 使用键值创建yml
我的Springboot中有一个.yml,我正在尝试用java类(key/value)在我的.yml中创建一个数组,但在执行应用程序时出错 Yml: 然后,我使用我的类配置文件在我的工具中获取数据:Java 使用键值创建yml,java,spring-boot,Java,Spring Boot,我的Springboot中有一个.yml,我正在尝试用java类(key/value)在我的.yml中创建一个数组,但在执行应用程序时出错 Yml: 然后,我使用我的类配置文件在我的工具中获取数据: @Value("${profiles}") private List<Profile> profiles; 错误: org.springframework.beans.factory.BeanCreationException: Error creating bean with nam
@Value("${profiles}")
private List<Profile> profiles;
错误:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'api': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'profiles' in value "${profiles}"
我要读取我的yml以查看校验值:
for (int i = 0; i < this.profiles.size(); i++) {
Profile pr = this.profiles.get(i);
System.out.println(pr.getType() + pr.getUrl());
}
啊!!我的个人资料可以有2,4,1000个注册表。。。这就是为什么我选择它的原因
@Value("${profiles}")
private List<Profile> profiles;
@Value(“${profiles}”)
私人名单简介;
这有帮助吗?你能提供你的应用程序的主要入口点和配置吗?@tmarwen我只读yml。@Smile perfect ty!!
for (int i = 0; i < this.profiles.size(); i++) {
Profile pr = this.profiles.get(i);
System.out.println(pr.getType() + pr.getUrl());
}
profiles: [
{
'key':'user',
'url': 'www'
},
{
'key':'admin',
'url': 'http'
}
]
@Value("${profiles}")
private List<Profile> profiles;