문제
spring batch quartz 설정중에 . jndiURl로 설정하면 spring-batch-infrastructure.jar (org.springframework.batch.support.DatabaseType)에서 지원하지 않는 DB는 아래와 같이 오류가 발생한다.
java.lang.IllegalArgumentException: DatabaseType not found for product name: [CUBRID]
at org.springframework.batch.support.DatabaseType.fromProductName(DatabaseType.java:82)
at org.springframework.batch.support.DatabaseType.fromMetaData(DatabaseType.java:121)
1차 문제 해결
import javax.sql.DataSource;
import org.springframework.batch.core.configuration.annotation.DefaultBatchConfigurer;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.repository.support.JobRepositoryFactoryBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.PlatformTransactionManager;
@Configuration
@EnableBatchProcessing
public class BatchConfigurer extends DefaultBatchConfigurer {
@Autowired
@Qualifier("datasource")
private DataSource dataSource;
@Autowired
@Qualifier("dataSourceTx")
private PlatformTransactionManager transactionManager;
public BatchConfigurer() {
super();
}
@Override
protected JobRepository createJobRepository() throws Exception {
JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean();
factory.setDataSource(dataSource);
factory.setDatabaseType("H2"); // 지원하지 않는 DB와 유사한 지원되는 DB를 지정해준다.
factory.setTransactionManager(transactionManager);
factory.afterPropertiesSet();
return factory.getObject();
}
}
2차 문제
quartz 만 사용해서 batch 를 사용하려고 했는데 jndi 를 사용하니 quartz db & batch 관련 db까지 만들어서 사용하는 문제가 발생
Caused by: cubrid.jdbc.driver.CUBRIDException: Syntax: Unknown class "batch_job_instance". select JOB_INSTANCE_ID, JOB_NAME from BATCH_JOB_INSTANCE whe...[CAS INFO-192.168.56.101:30000,2,3728],[SESSION-13900],[URL-jdbc:cubrid:192.168.56.101:30000:pencake:pencake:********:].
at cubrid.jdbc.jci.UConnection.createJciException(UConnection.java:2220)
at cubrid.jdbc.jci.UInputBuffer.<init>(UInputBuffer.java:117)
at cubrid.jdbc.jci.UConnection.send_recv_msg(UConnection.java:1785)
at cubrid.jdbc.jci.UConnection.send_recv_msg(UConnection.java:1797)
at cubrid.jdbc.jci.UConnection.prepareInternal(UConnection.java:997)
at cubrid.jdbc.jci.UConnection.prepare(UConnection.java:1035)
at cubrid.jdbc.jci.UConnection.prepare(UConnection.java:1016)
at cubrid.jdbc.driver.CUBRIDConnection.prepare(CUBRIDConnection.java:642)
at cubrid.jdbc.driver.CUBRIDConnection.prepare(CUBRIDConnection.java:811)
at cubrid.jdbc.driver.CUBRIDConnection.prepareStatement(CUBRIDConnection.java:162)
at org.apache.tomcat.dbcp.dbcp2.DelegatingConnection.prepareStatement(DelegatingConnection.java:302)
at org.apache.tomcat.dbcp.dbcp2.DelegatingConnection.prepareStatement(DelegatingConnection.java:302)
2차 해결
이렇게 하면 batch 테이블을 체크 하지 않음.
package com.ytech.gain.app.job.config;
import javax.sql.DataSource;
import org.springframework.batch.core.configuration.annotation.DefaultBatchConfigurer;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.repository.support.JobRepositoryFactoryBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.PlatformTransactionManager;
@Configuration
@EnableBatchProcessing
public class BatchConfigurer extends DefaultBatchConfigurer {
@Autowired
@Qualifier("datasource")
private DataSource dataSource;
@Autowired
@Qualifier("dataSourceTx")
private PlatformTransactionManager transactionManager;
public BatchConfigurer() {
super();
}
@Override
protected JobRepository createJobRepository() throws Exception {
JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean();
factory.setDataSource(dataSource);
factory.setDatabaseType("H2"); // 지원하지 않는 DB와 유사한 지원되는 DB를 지정해준다.
factory.setTransactionManager(transactionManager);
factory.afterPropertiesSet();
return factory.getObject();
}
// 이부분을 추가
@Override
public void setDataSource(DataSource dataSource) {
//super.setDataSource(dataSource);
}
}