Spring+myBatis 환경설정

2018. 10. 13. 22:58Spring Batch

반응형

context-mapper.xml 설정


  • 스프링 Application Context 영역에 myBatis 설정 공유
  • myBatis 설정 정보 위치 설정
  • 개발 SQL 파일 위치 설정
  • SqlSessionTemplate 설정
<?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"
	xsi:schemaLocation="http://www.springframework.org/schema/beans
						http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
						http://www.springframework.org/schema/batch
						http://www.springframework.org/schema/batch/spring-batch-2.1.xsd">
						
	<!-- myBatis 설정 -->
	<bean id="sqlSession" class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="dataSource" ref="dataSource" />
		<property name="configLocation" value="classpath:/config/sqlmap/sql-mapper-config.xml" />
		<property name="mapperLocations" value="classpath:/config/sqlmap/**/*SQL.xml" />
	</bean>
	
	<bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate">
		<constructor-arg index="0" ref="sqlSession" />
		<constructor-arg index="1" value="SIMPLE" />
	</bean>
	
	<bean id="batchSqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate">
		<constructor-arg index="0" ref="sqlSession" />
		<constructor-arg index="1" value="BATCH" />
	</bean>
</beans>

※ SqlSessionTemplate 은 생성자 주입을 사용하는데 두번째 인자는 value 의 의미는 ExecutorType을 의미

   ExecutorType에는 3가지 종류가 있음

   - SIMPLE, REUSE, BATCH



sql-mapper-config.xml 설정


  • myBatis 환경 설정
<?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="true" />
		<setting name="useColumnLabel" value="true" />
		<setting name="useGeneratedKeys" value="false" />
		<setting name="mapUnderscoreToCamelCase" value="true" />
		<setting name="defaultStatementTimeout" value="25000" />  
		<setting name="mapUnderscoreToCamelCase" value="true" />  
		<setting name="jdbcTypeForNull" value="NULL"/>
	</settings>
	<typeAliases>
		<package name="com.batchguide.dto"/>
	</typeAliases>
</configuration>


context-base 설정 업데이트


<?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"
	xsi:schemaLocation="http://www.springframework.org/schema/beans
						http://www.springframework.org/schema/beans/spring-beans.xsd
						http://www.springframework.org/schema/batch
						http://www.springframework.org/schema/batch/spring-batch.xsd">
	  
	<import resource="classpath:/config/batch/context-batch-job-launcher.xml" />					
	<import resource="classpath:/config/batch/context-batch-datasource.xml" />
	<import resource="classpath:/config/batch/context-batch-transaction.xml" />	
	<import resource="classpath:/config/batch/context-mapper.xml" />	
	<import resource="classpath:/config/batch/job/*.xml" />
				
</beans>						

※ context-mapper.xml 추가


[소스레파지토리]

☞ https://github.com/roopy1210/springbatch/blob/master/spring_batch_tutorial

반응형

'Spring Batch' 카테고리의 다른 글

FILE TO DB - Fixed Length 예제  (0) 2018.10.22
FILE TO DB - Delimiter 예제  (0) 2018.10.14
Hello Friends 예제 - 2  (0) 2018.09.29
Hello Friends 예제 - 1  (0) 2018.09.27
스프링 배치 환경 설정하기  (0) 2018.09.19