Amazon

Friday, May 25, 2012

Reading properties files in Spring


1. Inject to properties file in Spring Bean using PropertyPlaceholderConfigurer

bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    
        classpath:com/foo/jdbc.properties
    

2. Use the injected properties in your bean class. Here taking example of dataSource.

    ${jdbc.driverClassName}"/>
    ${jdbc.url}"/>
    ${jdbc.username}"/>
    ${jdbc.password}"/>

3. The Content of properties file is below 

The actual values come from another file in the standard Java
        Properties format:
jdbc.driverClassName=org.hsqldb.jdbcDriver
jdbc.url=jdbc:hsqldb:hsql://production:9002
jdbc.username=sa
jdbc.password=root

No comments:

Post a Comment

Amazon Best Sellors

Weblogic - Server Creation - Issues

Datasource creation using python script.  Python Script was failing after creating Datasource. From UI Admin Console, if I try to activat...