servlet-context.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<!-- new -->
<!-- DI -->
<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->
<!-- Enables the Spring MVC @Controller programming model -->
<mvc:annotation-driven />
<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<mvc:resources mapping="/resources/**" location="/resources/" />
<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>
<context:component-scan base-package="com.test.jjdev" />
<!-- 커넥션 풀 설정 -->
<!--
BasicDataSource dataSource = new BasicDataSource();
dataSource.setDriverClassName(driverClassName);
.
.
.
for() {
dataSource.list.add(connection);
}
-->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://127.0.0.1:3306/ksmart?useUnicode=true&characterEncoding=utf8"/>
<property name="username" value="root"/>
<property name="password" value="java0000"/>
</bean>
<!-- mybatis설정 1. SqlSessionFactory -->
<!--
SqlSessionFactoryBean sqlSessionFactory = new SqlSessionFactoryBean();
-->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- mybatis 세션생성시 사용할 dataSource주입 -->
<!--
sqlSessionFactory.setDataSource(dataSource);
value와 ref의 차이 정리하기
-->
<property name="dataSource" ref="dataSource" />
<!-- mybatis 세션생성후 쿼리를 실행시킬때 사용할 쿼리위치(메퍼)설정 -->
<property name="mapperLocations">
<list>
<value>classpath:com/test/jjdev/service/BoardMapper.xml</value>
<value>classpath:com/test/jjdev/service/MemberMapper.xml</value>
</list>
</property>
</bean>
<!-- mybatis설정 2. SqlSessionTemplate-->
<bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate">
<!-- new SqlSessionTemplate(sqlSessionTemplate) -->
<constructor-arg index="0" ref="sqlSessionFactory" />
</bean>
</beans>