PropertySourcesPlaceholderConfigurer no se registra con el entorno en un proyecto SpringBoot
Estoy moviendo un proyecto de trabajo de usar los argumentos de la línea de comandos de SpringBoot para leer las propiedades de un archivo. Aquí están las partes involucradas de la@Configuration
clase:
@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
}
Utilizando@Value
inyectar las propiedadeshace trabajo, sin embargo prefiero trabajar con elEnvironment
directamente si es posible. Si los ajustes no están en elEnvironment
entonces no estoy exactamente seguro de dónde@Value
los está tirando de ...
env.getProperty()
Sigue funcionando bien cuando paso los argumentos de la línea de comandos especificando las propiedades.
Cualquier sugerencia es bienvenida!