I would like to add a PropertySource
to a Spring Environment
before the context is refreshed via XML config.
The Java config way to do this is:
@Configuration
@PropertySource("classpath:....")
public ConfigStuff {
// config
}
And guess somehow magically @PropertySource
will be processed before the context is refreshed/initialized.
However I want to do some more dynamic stuff than just load from classpath.
The only way I know how to configure the Environment
before context is refreshed is to implement a ApplicationContextInitializer<ConfigurableApplicationContext>
and register it.
I stress the register part as this requires telling your environment about the context initializer through the servlet context and/or in case of a unit test adding @ContextConfiguration(value="this I don't mind", initializers="this I don't want to specify")
for every unit test.
I would rather my custom initializer or really in my case custom PropertySource get loaded via the application context xml file at the right time just like how @PropertySource
appears to work.