Код: Выделить всё
project:
component:
users:
default:
username: "JohnDoe"
anotherUser:
username: "AliceSmith"
Код: Выделить всё
@Getter
@Setter
@Accessors(fluent = false)
@ConfigurationProperties(prefix = "project.component")
@Component
public class AppProperties {
private UsersConfiguration users = new UsersConfiguration();
@Bean
UsersConfiguration users() {
return users;
}
}
Код: Выделить всё
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class UsersConfiguration {
private Map users = new HashMap();
}
Код: Выделить всё
public record User(String username) {}
Компонент user доступен через метод пользователей() в AppProperties. Однако при отладке поле пользователей в AppProperties пусто (размер = 0), хотя конфигурация YAML содержит действительные данные.
Вопросы:
- Почему карта пользователей в AppProperties пуста, хотя файл YAML кажется правильным?
- Необходимы ли дополнительные шаги или настройки для привязки YAML? в Map в Spring Boot?
Проверено, что структура YAML соответствует ожидаемому формату Map.
Подробнее здесь: https://stackoverflow.com/questions/793 ... -in-spring