DB정보를 jdbc.properties 파일로 분리하기..


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
		http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">

	<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<property name="locations">
			<value>classpath:jdbc.properties</value>
		</property>
	</bean>
	
	<!-- JNDI 로 datasource를 받아오는 경우 -->
	<!--  
	<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
		<property name="jndiName" value="${jdbc.datasource}"/>
    <property name="resourceRef" value="true" />
	</bean>
	-->
	 
	<bean id="dataSource" class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
		<property name="driverClass" value="${db.jdbc.driver}"/>
		<property name="url" value="${db.jdbc.url}"/>
		<property name="username" value="${db.user}"/>
		<property name="password" value="${db.password}"/>
	</bean>
	
	<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="dataSource" ref="dataSource" />
		<property name="configLocation" value="classpath:/META-INF/mybatis/mybatis-config.xml"/>
	</bean>
	
	<bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate">
		<constructor-arg ref="sqlSessionFactory"/>
	</bean>
</beans>


jdbc.properties


db.jdbc.driver=com.microsoft.sqlserver.jdbc.SQLServerDriver
db.jdbc.url=jdbc:sqlserver://서버명:포트;DatabaseName=DB명
db.user=사용자아이디
db.password=패스워드