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

TOGAF 9.2 - STUDY [ The Open Group Architecture Framework ] - Chap 01 - Introduction

100 Feet View of TOGAF  What is Enterprise? Collection of Organization that has common set of Goals. Enterprise has People - organized by co...