I'm looking for a way to manipulate @ConfigurationProperties
defined on initialization so that when I @Inject / @Autorwired
the configured object using a @Bean
method it is properly configured.
Scenario:
I have a bunch of properties set in a .yml
file. Because all of these properties match as Strings some of them need special handling to be properly configured to their respective types (some of them are enums). Do I make my properties object a @Component
then inject it into the @Bean
method and modify it? I tried to combine @Bean
and @ConfigurationProperties
annotations but the object is configured AFTER the @Bean
method itself returns, so any manipulation is lost/impossible. What is the best way to do this?
Example:
In my .yml
i have this:
properties:
sports:
"football": ["Team 1", "Team 2", "Team 3"]
"basketball": ["Team 4", "Team 5", "Team 6"]
settings:
"football":
"period1": "45"
"period2": "90"
"players": "11"
"basketball":
"periods": "4"
"players": "5"
And these match with the following objects:
Map<SportsEnum, List<TeamsEnum>
Map<SportsEnum, Map<SportSettingsEnum, String>>
TL;DR:
I want to take an object configured from a .yml/.properties
file and manipulate its injectable representation. Please provide concrete example!
Map<EnumKey, List<EnumValue>>
or evenMap<EnumKey1, Map<EnumKey2, EnumValue>>
.yml
and what you expect in java.