title: Hibernate using fully JavaConfig aproach in a Spring Batch Job
body: <p>I have a batch job fully configured using JavaConfig. having difficulties, mainly due to little material I found on configuration using only java. In the spring batch manual itself there is no information on how to fully configure a job with spring batch using only java. I do not know if it's because this configuration model is more recent than the xml based aprouch...</p>
  
  <p>Right now I'm having trouble setting up hibernate using this configuration class. I have an xml settings, but I'm not knowing how to reference it or how to change these settings for a fully "JavaConfig" version.</p>
  
  <p>My job configuration class is:</p>
  
  <pre><code>@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&lt;Flow&gt; builder = new FlowBuilder&lt;&gt;("flow1");
          builder.start(step0())
                  .next(step1())
                  .end();
          return builder.build();
      }
  
  
      @Bean
      protected Step step1() {
          return steps.get("processProductStep")
                  .&lt;TransferObject, Product&gt;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&lt;TransferObject, Product&gt; processor() {
          return new ProductProcessor();
      }
  
      @Bean
      public ItemReader&lt;TransferObject&gt; reader() {
          return new ProductItemReader();
      }
  
      @Bean
      public ItemWriter&lt;Product&gt; 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();
      }
  }
  </code></pre>
  
  <p>And the hibernate config file: </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;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"&gt;
  
      &lt;!-- Hibernate session factory --&gt;
      &lt;bean id="sessionFactory"
            class="org.springframework.orm.hibernate5.LocalSessionFactoryBean"&gt;
  
          &lt;property name="dataSource"&gt;
              &lt;ref bean="dataSource"/&gt;
          &lt;/property&gt;
  
          &lt;property name="hibernateProperties"&gt;
              &lt;props&gt;
                  &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/prop&gt;
                  &lt;prop key="hibernate.show_sql"&gt;true&lt;/prop&gt;
                  &lt;prop key="hbm2ddl.auto"&gt;update&lt;/prop&gt;
                  &lt;prop key="current_session_context_class"&gt;thread&lt;/prop&gt;
  
              &lt;/props&gt;
          &lt;/property&gt;
  
          &lt;property name="annotatedClasses"&gt;
              &lt;list&gt;
                  &lt;value&gt;br.com.alexpfx.supermarket.domain.Product&lt;/value&gt;
                  &lt;value&gt;br.com.alexpfx.supermarket.domain.Manufacturer&lt;/value&gt;
              &lt;/list&gt;
          &lt;/property&gt;
  
      &lt;/bean&gt;
  &lt;/beans&gt;
  </code></pre>