Spring Batch (2) - DataSource를 mysql 변경하기
DataSource 변경 하기
Spring batch template의 테스트 코드를 mysql로 변경 하기 위해
아래와 같이 properties 파일만 변경해 보았다.
참고로 spring batch에서는 dataSouce에 대한 지정이 안되어있으면 기본으로는 HSQLDB가 설정 되어있다.
>> 여기서 고민해야 할 부분은 repository에 대한 영속성을 가질 것이냐 말것이냐.
일단 영속성이 필요로 할것 같아 batch.properties를 아래와 같이 변경하였다.
batch.jdbc.driver=com.mysql.jdbc.Driver
batch.jdbc.url=jdbc:mysql://localhost/tablespace?characterEncoding=utf8
batch.jdbc.user=userid
batch.jdbc.password=password
batch.schema.script=classpath:/org/springframework/batch/core/schema-mysql.sql
문제는 이렇게 변경하고 2회째 수행 할 경우 다음과 같은 오류가 발생한다.
Table 'batch_job_instance' already exists
HSQLDB를 사용하였을 경우는 실행시 마다 테이블을 생성 해도 문제가 발생하지 않지만 (메모리 DB이기 때문에) MYSQL를 사용하였을 경우는 초회 실행시 테이블이 생성되고, 반복 실행 시 생성 스크립트가 호출되서 문제가 발생 한것 같다.
관련 properties
batch.schema.script=classpath:/org/springframework/batch/core/schema-mysql.sql
관련 bean context config
<jdbc:initialize-database data-source="dataSource">
<jdbc:script location="${batch.schema.script}" />
</jdbc:initialize-database>
현재 확인한 해결 방법으로는
=_= 해당 config 구문 주석 처리.
주석으로 처리하기 찜찜하여
이를 profile를 이용하여 생성 initialize-database의 profile 등록
<beans profile="first">
<jdbc:initialize-database data-source="dataSource">
<jdbc:script location="${batch.schema.script}" />
</jdbc:initialize-database>
</beans>
CF ) schemaLocation 변경 해야 <beans> 테그 사용가능
xsi:schemaLocation="
http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.1.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.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-3.0.xsd">
Eclipse에서 실행 설정 변경
>Run Configurations > Arguements > VM arguements 에
-Dspring.profiles.active=first 추가
Spring batch template의 테스트 코드를 mysql로 변경 하기 위해
아래와 같이 properties 파일만 변경해 보았다.
참고로 spring batch에서는 dataSouce에 대한 지정이 안되어있으면 기본으로는 HSQLDB가 설정 되어있다.
>> 여기서 고민해야 할 부분은 repository에 대한 영속성을 가질 것이냐 말것이냐.
일단 영속성이 필요로 할것 같아 batch.properties를 아래와 같이 변경하였다.
batch.jdbc.driver=com.mysql.jdbc.Driver
batch.jdbc.url=jdbc:mysql://localhost/tablespace?characterEncoding=utf8
batch.jdbc.user=userid
batch.jdbc.password=password
batch.schema.script=classpath:/org/springframework/batch/core/schema-mysql.sql
문제는 이렇게 변경하고 2회째 수행 할 경우 다음과 같은 오류가 발생한다.
Table 'batch_job_instance' already exists
HSQLDB를 사용하였을 경우는 실행시 마다 테이블을 생성 해도 문제가 발생하지 않지만 (메모리 DB이기 때문에) MYSQL를 사용하였을 경우는 초회 실행시 테이블이 생성되고, 반복 실행 시 생성 스크립트가 호출되서 문제가 발생 한것 같다.
관련 properties
batch.schema.script=classpath:/org/springframework/batch/core/schema-mysql.sql
관련 bean context config
<jdbc:initialize-database data-source="dataSource">
<jdbc:script location="${batch.schema.script}" />
</jdbc:initialize-database>
현재 확인한 해결 방법으로는
=_= 해당 config 구문 주석 처리.
주석으로 처리하기 찜찜하여
이를 profile를 이용하여 생성 initialize-database의 profile 등록
<beans profile="first">
<jdbc:initialize-database data-source="dataSource">
<jdbc:script location="${batch.schema.script}" />
</jdbc:initialize-database>
</beans>
CF ) schemaLocation 변경 해야 <beans> 테그 사용가능
xsi:schemaLocation="
http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.1.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.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-3.0.xsd">
Eclipse에서 실행 설정 변경
>Run Configurations > Arguements > VM arguements 에
-Dspring.profiles.active=first 추가
댓글
댓글 쓰기