Rob Gordon is a seasoned Java developer and a big fan of open source. Oddjob is his own open source project to make job scheduling and task automation in Java much much easier. Rob is based in London. Rob is a DZone MVB and is not an employee of DZone and has posted 17 posts at DZone. You can read more from them at their website. View Full User Profile

A Simpler Custom Property in Spring

06.07.2012
| 2728 views |
  • submit to reddit

I previously presented a CustomPropertyConfgurer that allows properties outside of Spring to be accessed from within Spring. The article was syndicated by DZone where a reader noted that in fact the Spring class PropertySourcesPlaceholderConfigurer has a setProperties method, and so for my particular example, the CustomPropertyConfigurer was redundant.

For the record, my previous example reduces to this:

public static void main(String... args) {
 
    char[] password = System.console().readPassword("Password: ");
 
    Properties properties = new Properties();
    properties.setProperty("jdbc.password", new String(password));
 
    ConfigurableApplicationContext context =
            new ClassPathXmlApplicationContext(
                new String[] { "rob/MyQuery.xml" },
                false);
 
    PropertySourcesPlaceholderConfigurer configurer =
                new PropertySourcesPlaceholderConfigurer();
 
    configurer.setProperties(properties);
    configurer.setIgnoreUnresolvablePlaceholders(true);
 
    context.addBeanFactoryPostProcessor(configurer);       
 
    context.refresh();
 
    MyQuery myQuery = context.getBean(MyQuery.class);
 
    myQuery.run();
 
    context.close();
}

However the motivation behind my foray into Spring property configuration is to improve Oddjob’s integration with Spring. My CustomPropertyConfigurer has now become an OddjobPropertyConfigurer

Published at DZone with permission of Rob Gordon, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

Fahmeed Nawaz replied on Tue, 2012/06/12 - 10:43am

The Mongo object instance actually represents a pool of connections to the database" ,does it mean that connection can be recycled? looking for your reply.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.