/**
 *    Copyright 2016-2019 the original author or authors.
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */
package examples.springbatch;

import static examples.springbatch.PersonDynamicSqlSupport.*;
import static org.mybatis.dynamic.sql.SqlBuilder.*;

import javax.sql.DataSource;

import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.dynamic.sql.select.SelectDSL;
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
import org.mybatis.dynamic.sql.update.render.UpdateStatementProvider;
import org.mybatis.dynamic.sql.util.springbatch.SpringBatchUtility;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.annotation.MapperScan;
import org.mybatis.spring.batch.MyBatisBatchItemWriter;
import org.mybatis.spring.batch.MyBatisCursorItemReader;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.configuration.annotation.BatchConfigurer;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.batch.core.launch.support.RunIdIncrementer;
import org.springframework.batch.item.ItemProcessor;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.test.JobLauncherTestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.converter.Converter;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;

@EnableBatchProcessing
@Configuration
@MapperScan("examples.springbatch")
public class BatchConfiguration {
    
    @Autowired
    private JobBuilderFactory jobBuilderFactory;
    
    @Autowired
    private StepBuilderFactory stepBuilderFactory;
    
    @Bean
    public DataSource dataSource() {
        EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
        EmbeddedDatabase db = builder.setType(EmbeddedDatabaseType.HSQL)
                .addScript("classpath:/examples/springbatch/schema.sql")
                .addScript("classpath:/examples/springbatch/data.sql")
                .build();
        return db;
    }
    
    @Bean
    public BatchConfigurer batchConfigurer() {
        return new NoPersistenceBatchConfigurer();
    }
    
    @Bean
    public SqlSessionFactoryBean sqlSessionFactoryBean(DataSource dataSource) {
        SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
        bean.setDataSource(dataSource);
        return bean;
    }

    @Bean
    public JobLauncherTestUtils jobLauncherTestUtils(Job job) {
        return new JobLauncherTestUtils();
    }
    
    @Bean
    public MyBatisCursorItemReader<Person> reader(SqlSessionFactory sqlSessionFactory) {
        SelectStatementProvider selectStatement =  SelectDSL.select(person.allColumns())
                .from(person)
                .where(lastName, isEqualTo("flintstone"))
                .build()
                .render(SpringBatchUtility.SPRING_BATCH_READER_RENDERING_STRATEGY);
        
        MyBatisCursorItemReader<Person> reader = new MyBatisCursorItemReader<>();
        reader.setQueryId(PersonMapper.class.getName() + ".selectMany");
        reader.setSqlSessionFactory(sqlSessionFactory);
        reader.setParameterValues(SpringBatchUtility.toParameterValues(selectStatement));
        return reader;
    }
    
    @Bean
    public PersonProcessor processor() {
        return new PersonProcessor();
    }
    
    @Bean
    public MyBatisBatchItemWriter<Person> writer(SqlSessionFactory sqlSessionFactory,
            Converter<Person, UpdateStatementProvider> convertor) {
        MyBatisBatchItemWriter<Person> writer = new MyBatisBatchItemWriter<>();
        writer.setSqlSessionFactory(sqlSessionFactory);
        writer.setItemToParameterConverter(convertor);
        writer.setStatementId(PersonMapper.class.getName() + ".update");
        return writer;
    }
    
    @Bean
    public Converter<Person, UpdateStatementProvider> convertor() {
        return new UpdateStatementConvertor();
    }
    
    @Bean
    public Step step1(ItemReader<Person> reader, ItemProcessor<Person, Person> processor, ItemWriter<Person> writer) {
        return stepBuilderFactory.get("step1")
                .<Person, Person>chunk(10)
                .reader(reader)
                .processor(processor)
                .writer(writer)
                .build();
    }

    @Bean
    public Job importUserJob(Step step1) {
        return jobBuilderFactory.get("importUserJob")
                .incrementer(new RunIdIncrementer())
                .flow(step1)
                .end()
                .build();
    }
}

@@ -1430,88 +1430,8 @@
 ep;%0A
-import org.springframework.batch.core.configuration.annotation.BatchConfigurer;%0A
 impo
@@ -1512,16 +1512,16 @@
 essing;%0A
+
 import o
@@ -2072,24 +2072,85 @@
 ation.Bean;%0A
+import org.springframework.context.annotation.ComponentScan;%0A
 import org.s
@@ -2555,16 +2555,55 @@
 batch%22)%0A
+@ComponentScan(%22examples.springbatch%22)%0A
 public c
@@ -3180,127 +3180,8 @@
 ean%0A
-    public BatchConfigurer batchConfigurer() %7B%0A        return new NoPersistenceBatchConfigurer();%0A    %7D%0A    %0A    @Bean%0A
     
@@ -3392,32 +3392,32 @@
    %7D%0A%0A    @Bean%0A
+
     public JobLa
@@ -3457,15 +3457,8 @@
 ils(
-Job job
 ) %7B%0A

Use component scanning