PropertySourcesPlaceholderConfigurer nie rejestruje się w środowisku w projekcie SpringBoot
Przenoszę działający projekt z argumentów wiersza poleceń SpringBoot do odczytu właściwości z pliku. Oto zaangażowane części@Configuration
klasa:
@Configuration
class RemoteCommunication {
@Inject
StandardServletEnvironment env
@Bean
static PropertySourcesPlaceholderConfigurer placeholderConfigurer () {
// VERIFIED this is executing...
PropertySourcesPlaceholderConfigurer target = new PropertySourcesPlaceholderConfigurer()
// VERIFIED this files exists, is readable, is a valid properties file
target.setLocation (new FileSystemResource ('/Users/me/Desktop/mess.properties'))
// A Debugger does NOT show this property source in the inject Environment
target
}
@Bean // There are many of these for different services, only one shown here.
MedicalSorIdService medicalSorIdService () {
serviceInstantiator (MedicalSorIdService_EpicSoap, 'uri.sor.id.lookup.internal')
}
// HELPER METHODS...
private <T> T serviceInstantiator (final Class<T> classToInstantiate, final String propertyKeyPrimary) {
def value = retrieveSpringPropertyFromConfigurationParameter (propertyKeyPrimary)
classToInstantiate.newInstance (value)
}
private def retrieveSpringPropertyFromConfigurationParameter (String propertyKeyPrimary) {
// PROBLEM: the property is not found in the Environment
def value = env.getProperty (propertyKeyPrimary, '')
if (value.isEmpty ()) throw new IllegalStateException ('Missing configuration parameter: ' + "\"$propertyKeyPrimary\"")
value
}
Za pomocą@Value
wstrzyknąć właściwościrobi pracuję, ale wolę pracować zEnvironment
bezpośrednio, jeśli w ogóle możliwe. Jeśli ustawienia nie znajdują się wEnvironment
wtedy nie jestem do końca pewien gdzie@Value
wyciąga ich z ...
env.getProperty()
nadal działa dobrze, gdy przekazuję argumenty wiersza poleceń określające właściwości.
Wszelkie sugestie są mile widziane!