I have a .yml in my Springboot, I am trying create an array in my .yml with a class java (key/value), but I get error when I execute the app.
Yml:
profiles:
- type: user
url: www
- type: admin
url: http
Then I get datas in my implements using my class Profile:
@Value("${profiles}")
private List<Profile> profiles;
Finally my class:
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class Profile {
private String type;
private String url;
}
Error:
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}"
I want read my yml for check values:
for (int i = 0; i < this.profiles.size(); i++) {
Profile pr = this.profiles.get(i);
System.out.println(pr.getType() + pr.getUrl());
}
Please I need help, I search in google but only get "Arrays" ['1','2','3']
o two Arrays ...
I need a structure the key/value
profiles: [
{
'key':'user',
'url': 'www'
},
{
'key':'admin',
'url': 'http'
}
]
Ahh !! My profiles can have 2,4, 1000 registros... that's why I pick it up List
@Value("${profiles}")
private List<Profile> profiles;