fix: GconeSourceConfig 배치 스키마 초기화 추가 (BATCH_JOB_SEQ 시퀀스 테이블 자동 생성)

- batchSchemaInitializer 빈 추가: schema-drop-mysql.sql + schema-mysql.sql 실행
- jobRepository에 @DependsOn(batchSchemaInitializer) 추가하여 초기화 순서 보장
- spring.batch.jdbc.initialize-schema 미적용 우회 (커스텀 JobRepository 빈 충돌)
This commit is contained in:
이주일
2026-05-23 11:24:12 +09:00
parent 0bf03de005
commit 6cbdc36c71

View File

@@ -10,9 +10,13 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder; import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
import org.springframework.context.annotation.Primary; import org.springframework.context.annotation.Primary;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver; import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.jdbc.datasource.DataSourceTransactionManager; import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.jdbc.datasource.init.DataSourceInitializer;
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.transaction.annotation.EnableTransactionManagement;
@@ -61,7 +65,21 @@ public class GconeSourceConfig {
return new DataSourceTransactionManager(gconeDataSource); return new DataSourceTransactionManager(gconeDataSource);
} }
// Spring Batch 스키마 초기화 (BATCH_JOB_SEQ 등 시퀀스 테이블 생성)
@Bean(name = "batchSchemaInitializer")
public DataSourceInitializer batchSchemaInitializer(@Qualifier("gconeDataSource") DataSource gconeDataSource) {
ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
populator.addScript(new ClassPathResource("org/springframework/batch/core/schema-drop-mysql.sql"));
populator.addScript(new ClassPathResource("org/springframework/batch/core/schema-mysql.sql"));
populator.setContinueOnError(true);
DataSourceInitializer initializer = new DataSourceInitializer();
initializer.setDataSource(gconeDataSource);
initializer.setDatabasePopulator(populator);
return initializer;
}
@Bean @Bean
@DependsOn("batchSchemaInitializer")
public JobRepository jobRepository(@Qualifier("gconeTransactionManager") PlatformTransactionManager transactionManager, @Qualifier("gconeDataSource") DataSource gconeDataSource) throws Exception { public JobRepository jobRepository(@Qualifier("gconeTransactionManager") PlatformTransactionManager transactionManager, @Qualifier("gconeDataSource") DataSource gconeDataSource) throws Exception {
JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean(); JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean();
factory.setDataSource(gconeDataSource); factory.setDataSource(gconeDataSource);