在Spring批处理作业中使用完全JavaConfig aproach进行休眠

在Spring批处理作业中使用完全JavaConfig aproach进行休眠,spring,hibernate,spring-batch,batch-processing,Spring,Hibernate,Spring Batch,Batch Processing,我使用JavaConfig完全配置了批处理作业。有困难,主要是因为我在仅使用java的配置中发现的资料很少。在SpringBatch手册本身中,没有关于如何仅使用java完全配置SpringBatch作业的信息。我不知道这是否是因为这个配置模型比基于xml的aprouch更新 现在我在使用这个配置类设置hibernate时遇到了问题。我有一个xml设置,但我不知道如何引用它,或者如何更改这些设置以获得一个完整的“JavaConfig”版本 我的作业配置类是: @Configuration @En

我使用JavaConfig完全配置了批处理作业。有困难,主要是因为我在仅使用java的配置中发现的资料很少。在SpringBatch手册本身中,没有关于如何仅使用java完全配置SpringBatch作业的信息。我不知道这是否是因为这个配置模型比基于xml的aprouch更新

现在我在使用这个配置类设置hibernate时遇到了问题。我有一个xml设置,但我不知道如何引用它,或者如何更改这些设置以获得一个完整的“JavaConfig”版本

我的作业配置类是:

@Configuration
@EnableBatchProcessing
public class CrawlerBatchConfiguration {


    @Autowired
    private StepBuilderFactory steps;

    @Bean
    public Job job(JobBuilderFactory jobs) {
        return jobs.get("myJob").start(flow()).end().build();
    }

    protected Step step0() {
        return steps.get("setupCrawlerStep").tasklet(tasklet()).build();
    }

    private Flow flow() {
        FlowBuilder<Flow> builder = new FlowBuilder<>("flow1");
        builder.start(step0())
                .next(step1())
                .end();
        return builder.build();
    }


    @Bean
    protected Step step1() {
        return steps.get("processProductStep")
                .<TransferObject, Product>chunk(10)
                .reader(reader())
                .processor(processor())
                .writer(writer())
                .build();
    }

    @Bean
    protected Tasklet tasklet() {
        return new StartCrawlerTasklet();
    }


    @Bean
    protected ProductList getProductList() {
        return new ProductList();
    }

    @Bean
    public CrawlerListener listener() {
        CrawlerListener listener = new RibeiraoListener();
        return listener;
    }


    @Bean
    public ItemProcessor<TransferObject, Product> processor() {
        return new ProductProcessor();
    }

    @Bean
    public ItemReader<TransferObject> reader() {
        return new ProductItemReader();
    }

    @Bean
    public ItemWriter<Product> writer() {
        return new HIbernateProductsItemWriter();
    }


    @Bean
    public Crawler crawler() {
        return new RibeiraoCrawler(new UserAgentFactory());
    }

    @Bean
    public ProductBo productBo() {
        return new ProductBoImpl();
    }

    @Bean
    public ProductDao productDao() {
        return new ProductDaoImpl();
    }
}
@配置
@启用批处理
公共类CrawlerBatchConfiguration{
@自动连线
私人StepBuilderFactorySteps;
@豆子
公共作业作业(JobBuilderFactory作业){
return jobs.get(“myJob”).start(flow()).end().build();
}
受保护的步骤step0(){
返回steps.get(“setupCrawlerStep”).tasklet(tasklet()).build();
}
私有流{
FlowBuilder=新的FlowBuilder(“flow1”);
builder.start(step0())
.下一步(步骤1())
.end();
返回builder.build();
}
@豆子
受保护的步骤1(){
返回步骤。获取(“processProductStep”)
.chunk(10)
.reader(reader())
.processor(处理器())
.writer(writer())
.build();
}
@豆子
受保护的Tasklet Tasklet(){
返回新的StartCrawlerTasklet();
}
@豆子
受保护的ProductList getProductList(){
返回新产品列表();
}
@豆子
公共爬虫侦听器(){
CrawlerListener=new-RibeiraoListener();
返回侦听器;
}
@豆子
公共项目处理器(){
返回新的ProductProcessor();
}
@豆子
公共项目阅读器(){
返回新的ProductItemReader();
}
@豆子
公共项目编写器(){
返回新的HibernateProductSiteWriter();
}
@豆子
公共爬虫{
返回新的RibeiraoCrawler(new UserAgentFactory());
}
@豆子
公共产品{
返回新产品boImpl();
}
@豆子
公共产品{
返回新产品daoimpl();
}
}
和hibernate配置文件:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.2.xsd">

    <!-- Hibernate session factory -->
    <bean id="sessionFactory"
          class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">

        <property name="dataSource">
            <ref bean="dataSource"/>
        </property>

        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hbm2ddl.auto">update</prop>
                <prop key="current_session_context_class">thread</prop>

            </props>
        </property>

        <property name="annotatedClasses">
            <list>
                <value>br.com.alexpfx.supermarket.domain.Product</value>
                <value>br.com.alexpfx.supermarket.domain.Manufacturer</value>
            </list>
        </property>

    </bean>
</beans>

org.hibernate.dialogue.mysqldialogue
真的
更新
线
br.com.alexpfx.supermarket.domain.Product
br.com.alexpfx.supermarket.domain.Manufacturer

更新
:)@v.ladynev我不明白。自从我转到JavaConfig aproach之后,还没有读取这个配置文件。它只是一个不正确的属性名,仅此而已。我认为您需要添加一个JavaConfig示例。