Announcement Announcement Module
No announcement yet.
@Configuration, @PropertySource, @value and filesystem resources Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • @Configuration, @PropertySource, @value and filesystem resources


    I am new to Spring on the coding side, but have been working with spring based applications for a while on the operations front.

    I am having some trouble trying to externalise configuration injected using the @configuration and @propertysource annotations.

    "classpath:" incantations work, but trying to use "file:" fails

    here is the meat of the code.

    public class SpringMongoConfiguration {
    	private String mongoUrl;
    	private String mongoPort;
    	private String dbName;
    	private String username;
    	private String password;
    	public @Bean MongoDoubleTypeIdConverter doubleTypeIdConverter() throws Exception {
    		return new MongoDoubleTypeIdConverter(mongoDbFactory(), new MongoMappingContext());
    	public @Bean static PropertySourcesPlaceholderConfigurer mongoPropertySourcesPlaceholderConfigurer() {
    		PropertySourcesPlaceholderConfigurer myConfigurer = new PropertySourcesPlaceholderConfigurer();
    		return myConfigurer;
    in the application log, it appears to be working:

    17:14:42.620 [pool-2-thread-1] DEBUG o.s.w.c.s.StandardServletEnvironment - Adding [URL [file:/etc/product/]] PropertySource with lowest search precedence

    ... but later ...

    ... nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.product.dao.FacebookRecordRepositoryImpl.mongoOperations; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springMongoConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private java.lang.String com.product.config.SpringMongoConfiguration.mongoUrl; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'mongo.url' in string value [${mongo.url}]
    ... so the parameters are not being retained/ are not accessible when the configuration class is actually being instantiated.

    any pointers on this would be very helpful