I'm currently trying to convert a mostly-Java-with-some-XML Spring 3.0.6 configuration to a Java-only configuration with Spring 3.1.0.RC1.
In my old XML context, I use a property placeholder
where MY_CONFIG is an environment variable pointing to a properties file.Code:<context:property-placeholder location="file:${MY_CONFIG}"/>
What is the equivalent of this in a Java configuration?
Here is what currently works for me:
But I'm not sure if this is the best practice. In particular, the explicit lookup of the environment variable somehow doesn't feel right...Code:@Bean public static PropertySourcesPlaceholderConfigurer propertyConfigurer() { PropertySourcesPlaceholderConfigurer bean = new PropertySourcesPlaceholderConfigurer(); bean.setLocation(new FileSystemResource(System.getenv("MY_CONFIG"))); return bean; }
Best regards,
Harald


Reply With Quote