admin管理员组文章数量:1124668
I am trying to load the following YAML configuration into a Spring Boot application using @ConfigurationProperties:
project:
component:
users:
default:
username: "JohnDoe"
anotherUser:
username: "AliceSmith"
AppProperties class:
@Getter
@Setter
@Accessors(fluent = false)
@ConfigurationProperties(prefix = "projectponent")
@Component
public class AppProperties {
private UsersConfiguration users = new UsersConfiguration();
@Bean
UsersConfiguration users() {
return users;
}
}
UsersConfiguration class:
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class UsersConfiguration {
private Map<String, User> users = new HashMap<>();
}
User record:
public record User(String username) {}
The Problem:
The users
bean is exposed via the users()
method in AppProperties. However, when debugging, the users field in AppProperties is empty (size = 0), even though the YAML configuration contains valid data.
Questions:
- Why is the users map in AppProperties empty, even though the YAML file seems correct?
- Are there additional steps or configurations required to bind YAML into a Map<String, User> in Spring Boot?
Any help would be greatly appreciated! Thank you
Verified the YAML structure matches the expected Map<String, User> format.
版权声明:本文标题:java - @ConfigurationProperties map is empty when binding YAML configuration in Spring Boot - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736645886a1946101.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论