[샘플코드 : manager-servlet.xml]

<?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:p="http://www.springframework.org/schema/p" 

    xmlns:aop="http://www.springframework.org/schema/aop"

    xmlns:context="http://www.springframework.org/schema/context"

xmlns:tx="http://www.springframework.org/schema/tx"

    xmlns:oxm="http://www.springframework.org/schema/oxm"    

    xsi:schemaLocation="

        http://www.springframework.org/schema/beans 

        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

        http://www.springframework.org/schema/tx    

http://www.springframework.org/schema/tx/spring-tx-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/context 

        http://www.springframework.org/schema/context/spring-context-3.0.xsd

        http://www.springframework.org/schema/oxm

     http://www.springframework.org/schema/oxm/spring-oxm-3.0.xsd">

<context:component-scan base-package="com.manager" />


<tx:annotation-driven transaction-manager="transactionManager"/>

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">

    <property name="driverClassName" value="com.mysql.jdbc.Driver"/>

    <property name="url" value="jdbc:mysql://61.109.146.35:3306/test"/>     

    <property name="username" value="testid"/>

    <property name="password" value="testpwd"/>

    <property name="defaultAutoCommit" value="true"/>

    <property name="initialSize" value="5"/>

    <property name="maxActive" value="30"/>

    <property name="maxIdle" value="5"/>

    <property name="maxWait" value="30000"/>

    <property name="timeBetweenEvictionRunsMillis" value="60000"/>

</bean>

<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">

        <property name="dataSource" ref="dataSource"/>

    </bean>


    <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">

        <property name="configLocation" value="classpath:config/sqlMapConfig.xml"/>

        <property name="dataSource" ref="dataSource"/>

    </bean>

    

    <bean id="sqlMapClientTemplate"

class="org.springframework.orm.ibatis.SqlMapClientTemplate"

p:sqlMapClient-ref="sqlMapClient"/>

<bean

class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" p:alwaysUseFullPath="true" >

<property name="messageConverters">

<list>

<ref bean="stringHttpMessageConverter" />

<ref bean="marshallingHttpMessageConverter" />

</list>

</property>

</bean>

<bean id="stringHttpMessageConverter"

class="org.springframework.http.converter.StringHttpMessageConverter">

<property name="writeAcceptCharset" value="true" />

</bean>

<bean id="marshallingHttpMessageConverter"

class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter"

p:marshaller-ref="jaxb2Marshaller" p:unmarshaller-ref="jaxb2Marshaller" />

<oxm:jaxb2-marshaller id="jaxb2Marshaller" contextPath="com.manager.vo.vcard"/>

<bean id="viewResolver"

class="org.springframework.web.servlet.view.UrlBasedViewResolver">

<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>

<property name="prefix" value="/WEB-INF/view/"></property>

<property name="suffix" value=".jsp"></property>

</bean>


</beans>

manager-servlet.xml

-- servlet의 모든것이 중요하지만 체크해야 할점을 빨간색 마킹처리했다.

dataSource에는 dbproperties 파일로 빼놓는 경우도 있으나 DB접속 정보를 저장한다.

transactionManager를 선언 하고 DB를 설정한다.

sqlMapClient bean을 선언하고 sqlMapConfig.xml위치를 설정한다. 위의경우 소스폴더의 config패키지 아래에 생성된다.


'DB > iBatis' 카테고리의 다른 글

iBatis 구현 - 4 sqlMapConfig.xml  (0) 2012.03.29
iBatis에서 HashMap의 활용  (2) 2012.03.29
iBatis 구현 - 2 web.xml 수정  (0) 2012.03.28
iBatis 구현 - 1 대략적 개념  (0) 2012.03.28
iBatis 구현 (개인적)  (0) 2012.03.28

+ Recent posts