Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Caused by: java.lang.ClassNotFoundException: org.hibernate.ejb.HibernatePersistence
- at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
- at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
- at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
- at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
- ... 51 more
- Caused by: java.lang.NoClassDefFoundError: org/hibernate/ejb/HibernatePersistence
- at org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter.<init>(HibernateJpaVendorAdapter.java:57)
- at com.edf.fr.batch.MarcheBatchConfiguration.jpaVendorAdapter(MarcheBatchConfiguration.java:204)
- at com.edf.fr.batch.MarcheBatchConfiguration$$EnhancerBySpringCGLIB$$89ce9a5b.CGLIB$jpaVendorAdapter$6(<generated>)
- at com.edf.fr.batch.MarcheBatchConfiguration$$EnhancerBySpringCGLIB$$89ce9a5b$$FastClassBySpringCGLIB$$d4b1171.invoke(<generated>)
- at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
- at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:309)
- at com.edf.fr.batch.MarcheBatchConfiguration$$EnhancerBySpringCGLIB$$89ce9a5b.jpaVendorAdapter(<generated>)
- at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
- at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
- at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
- at java.lang.reflect.Method.invoke(Method.java:497)
- at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
- ... 39 more
- package com.edf.fr.batch;
- import java.sql.SQLException;
- import java.util.Properties;
- import javax.sql.DataSource;
- import org.springframework.batch.core.Job;
- import org.springframework.batch.core.Step;
- 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.item.database.JpaItemWriter;
- import org.springframework.batch.item.file.FlatFileItemReader;
- import org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper;
- import org.springframework.batch.item.file.mapping.DefaultLineMapper;
- import org.springframework.batch.item.file.transform.DelimitedLineTokenizer;
- import org.springframework.batch.test.JobLauncherTestUtils;
- import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
- import org.springframework.context.annotation.Bean;
- import org.springframework.context.annotation.ComponentScan;
- import org.springframework.context.annotation.Configuration;
- import org.springframework.core.io.ClassPathResource;
- import org.springframework.jdbc.core.JdbcTemplate;
- import org.springframework.jdbc.datasource.DriverManagerDataSource;
- import org.springframework.orm.jpa.JpaVendorAdapter;
- import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
- import org.springframework.orm.jpa.vendor.Database;
- import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
- /**
- * This class contains all the configuration of the Spring Batch application
- * used for this tutorial. It contains readers, writers, processors, jobs, steps
- * and all the needed beans.
- * @author dgutierrez-diez
- */
- @Configuration
- @EnableBatchProcessing
- @ComponentScan
- @EnableAutoConfiguration
- public class MarcheBatchConfiguration {
- /**
- * Modes, should be injected as parameter TODO
- */
- /*
- * ********************************************
- * READERS This section contains all the readers
- * ********************************************
- */
- /**
- * @return a reader
- */
- @Bean
- public ItemReader<CustomPojo> reader() {
- System.out.println("Inside item reader");
- // flat file item reader (using an csv extractor)
- FlatFileItemReader<CustomPojo> reader = new FlatFileItemReader<CustomPojo>();
- reader.setResource(new ClassPathResource("input.csv"));
- reader.setLineMapper(new DefaultLineMapper<CustomPojo>() {
- {
- setLineTokenizer(new DelimitedLineTokenizer() {
- {
- setNames(new String[] { "id", "description" });
- }
- });
- setFieldSetMapper(new BeanWrapperFieldSetMapper<CustomPojo>() {
- {
- setTargetType(CustomPojo.class);
- }
- });
- }
- });
- return reader;
- }
- /*
- * ********************************************
- * PROCESSORS This section contains all processors
- * ********************************************
- */
- /**
- * @return custom item processor -> anything
- */
- @Bean
- public ItemProcessor<CustomPojo, CustomPojo> processor() {
- return new CustomItemProcessor();
- }
- /*
- * ********************************************
- * WRITERS This section contains all the writers
- * ********************************************
- */
- /**
- * @param dataSource
- * @return dummy item writer custom
- * @throws SQLException
- */
- @Bean
- public ItemWriter<CustomPojo> writer(DataSource dataSource) throws SQLException {
- System.out.println("Inside item writer");
- /*
- * JdbcBatchItemWriter<CustomPojo> writer = new JdbcBatchItemWriter<CustomPojo>();
- * writer.setSql("INSERT INTO pojocheck (id, description) VALUES (:id, :description)");
- * writer.setDataSource(dataSource);
- * writer.setItemSqlParameterSourceProvider(new BeanPropertyItemSqlParameterSourceProvider<CustomPojo>());
- */
- JpaItemWriter<CustomPojo> writer = new JpaItemWriter<CustomPojo>();
- writer.setEntityManagerFactory(entityManagerFactory().getObject());
- return writer;
- }
- /*
- * ********************************************
- * JOBS ***************************************
- * ********************************************
- */
- /**
- * @param jobs
- * @param s1
- * steps
- * @return the Job
- */
- @Bean
- public Job importUserJob(JobBuilderFactory jobs, Step s1) {
- return jobs.get("importUserJob").incrementer(new RunIdIncrementer()).flow(s1).end().build();
- }
- /*
- * ********************************************
- * STEPS **************************************
- * ********************************************
- */
- /**
- * the step 1 contains a reader a processor and a writer using a chunk of 10
- * @param stepBuilderFactory
- * @param reader
- * @param writer
- * @param processor
- * @return
- */
- @Bean
- public Step step1(StepBuilderFactory stepBuilderFactory, ItemReader<CustomPojo> reader,
- ItemWriter<CustomPojo> writer, ItemProcessor<CustomPojo, CustomPojo> processor) {
- /* it handles bunches of 10 units */
- return stepBuilderFactory.get("step1").<CustomPojo, CustomPojo> chunk(10).reader(reader)
- .processor(processor).writer(writer).build();
- }
- /*
- * ********************************************
- * UTILITY BEANS ******************************
- * ********************************************
- */
- /**
- * jdbc template (hsqldb)
- * @param dataSource
- * @return JdbcTemplate
- */
- @Bean
- public JdbcTemplate jdbcTemplate(DataSource dataSource) {
- return new JdbcTemplate(dataSource);
- }
- @Bean
- public DataSource dataSource() throws SQLException {
- final DriverManagerDataSource dataSource = new DriverManagerDataSource();
- dataSource.setDriverClassName("org.postgresql.Driver");
- dataSource.setUrl("jdbc:postgresql://localhost:5432/engc_local");
- dataSource.setUsername("postgres");
- dataSource.setPassword("postgres");
- return dataSource;
- }
- @Bean
- public LocalContainerEntityManagerFactoryBean entityManagerFactory() throws SQLException {
- LocalContainerEntityManagerFactoryBean lef = new LocalContainerEntityManagerFactoryBean();
- lef.setDataSource(dataSource());
- lef.setJpaVendorAdapter(jpaVendorAdapter());
- lef.setJpaProperties(new Properties());
- lef.setPackagesToScan("com.edf.fr");
- return lef;
- }
- @Bean
- public JpaVendorAdapter jpaVendorAdapter() {
- HibernateJpaVendorAdapter jpaVendorAdapter = new HibernateJpaVendorAdapter();
- jpaVendorAdapter.setDatabase(Database.POSTGRESQL);
- jpaVendorAdapter.setGenerateDdl(true);
- jpaVendorAdapter.setShowSql(true);
- jpaVendorAdapter.setDatabasePlatform("org.hibernate.dialect.PostgreSQLDialect");
- return jpaVendorAdapter;
- }
- /**
- * jobLauncherTestUtils utility class for testing batches
- * @return JobLauncherTestUtils
- */
- @Bean
- public JobLauncherTestUtils jobLauncherTestUtils() {
- return new JobLauncherTestUtils();
- }
- }
- package com.edf.fr.batch;
- import javax.persistence.Column;
- import javax.persistence.Entity;
- import javax.persistence.GeneratedValue;
- import javax.persistence.Id;
- import javax.persistence.Table;
- @Entity
- @Table(name = "Marche")
- public class CustomPojo {
- @Id
- @Column
- @GeneratedValue
- private String id;
- @Column
- private String description;
- public CustomPojo() {
- }
- public CustomPojo(String id, String description) {
- this.id = id;
- this.description = description;
- }
- @Override
- public String toString() {
- return id + "," + description;
- }
- public String getId() {
- return id;
- }
- public void setId(String id) {
- this.id = id;
- }
- public String getDescription() {
- return description;
- }
- public void setDescription(String description) {
- this.description = description;
- }
- }
- <?xml version="1.0" encoding="UTF-8"?>
- <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <groupId>com.edf.fr.batch</groupId>
- <artifactId>edf-marche-batch</artifactId>
- <version>0.1.0</version>
- <parent>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-parent</artifactId>
- <version>1.2.1.RELEASE</version>
- </parent>
- <dependencies>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-batch</artifactId>
- </dependency>
- <dependency>
- <groupId>org.hsqldb</groupId>
- <artifactId>hsqldb</artifactId>
- </dependency>
- <dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-java</artifactId>
- </dependency>
- <!-- Spring Batch unit test -->
- <dependency>
- <groupId>org.springframework.batch</groupId>
- <artifactId>spring-batch-test</artifactId>
- </dependency>
- <dependency>
- <groupId>postgresql</groupId>
- <artifactId>postgresql</artifactId>
- <version>9.1-901-1.jdbc4</version>
- </dependency>
- <dependency>
- <groupId>org.hibernate</groupId>
- <artifactId>hibernate-entitymanager</artifactId>
- <version>5.2.10.Final</version><!--$NO-MVN-MAN-VER$-->
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-orm</artifactId>
- <version>3.1.1.RELEASE</version><!--$NO-MVN-MAN-VER$-->
- </dependency>
- <!-- Junit -->
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
- </dependencies>
- <build>
- <plugins>
- <plugin>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-maven-plugin</artifactId>
- </plugin>
- </plugins>
- </build>
- </project>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement