본문 바로가기
programming/Spring

PropertyPlaceholderConfigurer

by hotdogya 2013. 1. 30.

jdbc 설정이나 log4j, message 이런거? 설정할 때 properties를 사용한다.


    <beans:bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <beans:property name="driverClassName" value="${db.Driver}"/>
        <beans:property name="url" value="${db.Url}"/>
        <beans:property name="username" value="${db.Username}"/>
        <beans:property name="password" value="${db.Password}"/>
    </beans:bean>


${} 이런 표현식을 사용하여 properties파일의 데이터를 읽어 올수 있다.




db.properties 파일에 설정 정보가 저장되어 있다.

jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/test
jdbc.username=root
jdbc.password=1234


이 데이터를 읽기 위해선 PropertyPlaceholderConfigurer 를 사용하여 데이터를 읽어 올 수 있다.



    <beans:bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <beans:property name="location">
            <beans:value>classpath:conf/jdbc.properties</beans:value>
        </beans:property>
    </beans:bean>


<context:property-placeholder location="classpath:conf/jdbc.properties"/>




//http://www.dator.co.kr/?mid=textyle&category=44981&vid=encore&document_srl=205646

http://blog.naver.com/minis24/80097770192

'programming > Spring' 카테고리의 다른 글

스프링 배치의 기본적인 흐름  (0) 2013.01.17