IT_Note


WEB-INF/mybatis/jdbc.properties   

jdbc오라클 환경 설정 파일. txt파일.

##jdbc.driverClass=oracle.jdbc.driver.OracleDriver
##jdbc.url=jdbc:oracle:thin:@127.0.0.1:1521:ORCL
jdbc.driverClass=net.sf.log4jdbc.DriverSpy
jdbc.url=jdbc:log4jdbc:oracle:thin:@127.0.0.1:1521:xe
jdbc.username=board1
jdbc.password=java$!


mybatis-config.xml    - mybatis환경설정 xml

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "HTTP://mybatis.org/dtd/mybatis-3-config.dtd">


<configuration>

<settings>

<setting name="cacheEnabled" value="false" />

<setting name="useGeneratedKeys" value="true" />

<setting name="defaultExecutorType" value="REUSE" />

</settings>

<!-- 별명 -->

    <typeAliases>

         <typeAlias alias="hashMap" type="java.util.HashMap" />

         <typeAlias alias="map" type="java.util.Map" />

    </typeAliases>

 

<!--

<mappers>

<mapper resource="mybatis/mapper/tempMapper.xml" />

</mappers>

-->


<mappers>

<mapper resource="mybatis/mapper/bbsMapper.xml" />

</mappers>

</configuration>




mybatis-context.xml  -  mybatis 객체 생성을 위한 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:aop="http://www.springframework.org/schema/aop"

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

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

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

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

xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd

http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd

http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd

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

    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">

<property name="locations">

<value>/WEB-INF/mybatis/jdbc.properties</value>

</property>

</bean>


    <!-- DBCP를 위한 DataSource 객체 -->

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

<property name="driverClassName" value="${jdbc.driverClass}"/>

<property name="url" value="${jdbc.url}"/>

<property name="username" value="${jdbc.username}"/>

<property name="password" value="${jdbc.password}"/>

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

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

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

  <property name="defaultAutoCommit" value="true" />   <!--  기본:true  -->

</bean>

<!--  SqlSessionFactoryBean : SqlSessionTemplate 객체를 얻는다. -->

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean" lazy-init="true">

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

<property name="configLocation" value="/WEB-INF/mybatis/mybatis-config.xml"/>

         <property name="mapperLocations" value="/WEB-INF/mybatis/mapper/*.xml" />

<!-- 

<property name="mapperLocations" value="classpath:com/think/mapper/**/*.xml" />

-->

         <!-- 

         <property name="transactionFactory">

                <bean class="org.apache.ibatis.transaction.managed.ManagedTransactionFactory" />

          </property>

           -->

</bean>


<!-- SqlSessionTemplate : MyBatis SQL method 호출 및 관리, 예외처리 담당 -->

    <bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">

           <constructor-arg index="0" ref="sqlSessionFactory" />

    </bean>


    <!-- 트랜잭션관리자. -->

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

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

    </bean>


<!-- 트랜잭션과 관련된 작업(트랜잭션시작, 커및, 롤백등) -->

    <bean id="transactionTemplate" class="org.springframework.transaction.support.TransactionTemplate">

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

    </bean>

     

</beans>



bbsMapper.xml  - 맵퍼

<?xml version="1.0" encoding="UTF-8"?>


<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="bbs">


</mapper>