Spring批处理---找不到产品名称的DatabaseType:[Informix Dynamic Server]

时间:2016-01-05 23:10:39

标签: spring-boot spring-batch

我想用Spring启动Spring Batch,因为我们使用的是informix数据库,当我的Spring启动应用程序启动时,我遇到了以下异常。

配置:

@Bean
public DataSource dataSource() throws SQLException {
   BasicDataSource dataSource = new BasicDataSource();
   dataSource.setDriverClassName(dataSourceProperties.getDriverClassName());
    dataSource.setUrl(dataSourceProperties.getDbUrl());
    dataSource.setUsername(dataSourceProperties.getDbUsername());
    dataSource.setPassword(dataSourceProperties.getDbPassword())
    return dataSource;
}


@Bean
public DataSourceTransactionManager dataSourceTransactionManager(DataSource dataSource){

    DataSourceTransactionManager manager=new DataSourceTransactionManager(dataSource);
    return manager;
}

@Bean
public JobRepositoryFactoryBean jobRepositoryFactoryBean( DataSourceTransactionManager txManager,DataSource dataSource ) throws Exception{

    JobRepositoryFactoryBean job=new JobRepositoryFactoryBean();
    job.setDataSource(dataSource);
    job.setDatabaseType("oracle");
    job.setTransactionManager(txManager);
    job.afterPropertiesSet();
    return job;
}


@Bean
public ItemReader<Person> reader() {
    FlatFileItemReader<Person> reader = new FlatFileItemReader<Person>();
    reader.setResource(new ClassPathResource("sample-data.csv"));
    reader.setLineMapper(new DefaultLineMapper<Person>() {{
        setLineTokenizer(new DelimitedLineTokenizer() {{
            setNames(new String[] { "firstName", "lastName" });
        }});
        setFieldSetMapper(new BeanWrapperFieldSetMapper<Person>() {{
            setTargetType(Person.class);
        }});
    }});
    return reader;
}

@Bean
public ItemProcessor<Person, Person> processor() {
    return new PersonItemProcessor();
}

@Bean
public ItemWriter<Person> writer(DataSource dataSource) {
    JdbcBatchItemWriter<Person> writer = new JdbcBatchItemWriter<Person>();
    writer.setItemSqlParameterSourceProvider(new BeanPropertyItemSqlParameterSourceProvider<Person>());
    writer.setSql("INSERT INTO people (first_name, last_name) VALUES (:firstName, :lastName)");
    writer.setDataSource(dataSource);
    writer.afterPropertiesSet();
    return writer;
}

@Bean
public Job importUserJob(JobBuilderFactory jobs, Step s1, JobExecutionListener listener,JobRepositoryFactoryBean jobRepositoryFactoryBean) throws Exception {


    return jobs.get("importUserJob")
             .repository(jobRepositoryFactoryBean.getObject())
            .incrementer(new RunIdIncrementer())
            .listener(listener)
            .flow(s1)
            .end()
            .build();
}

@Bean
public Step step1(StepBuilderFactory stepBuilderFactory, ItemReader<Person> reader,
        ItemWriter<Person> writer, ItemProcessor<Person, Person> processor) {
    return stepBuilderFactory.get("step1")
            .<Person, Person> chunk(10)
            .reader(reader)
            .processor(processor)
            .writer(writer)
            .build();
}

例外

由以下原因引起:java.lang.IllegalArgumentException:找不到产品名称的DatabaseType:[Informix Dynamic Server]     at org.springframework.batch.support.DatabaseType.fromProductName(DatabaseType.java:79)     在org.springframework.batch.support.DatabaseType.fromMetaData(DatabaseType.java:110)     at org.springframework.boot.autoconfigure.batch.BatchDatabaseInitializer.getDatabaseType(BatchDatabaseInitializer.java:71)     在org.springframework.boot.autoconfigure.batch.BatchDatabaseInitializer.initialize(BatchDatabaseInitializer.java:50)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     在java.lang.reflect.Method.invoke(Method.java:497)     at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor $ LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:349)     at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor $ LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:300)     at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:133)

1 个答案:

答案 0 :(得分:0)

Spring Batch似乎并不直接支持Informix。

来自org.springframework.batch.support.DatabaseType

DERBY("Apache Derby"), 
DB2("DB2"), 
DB2ZOS("DB2ZOS"), 
HSQL("HSQL Database Engine"),
SQLSERVER("Microsoft SQL Server"),
MYSQL("MySQL"),
ORACLE("Oracle"),
POSTGRES("PostgreSQL"),
SYBASE("Sybase"), H2("H2");

但是,如前所述:http://forum.spring.io/forum/spring-projects/batch/61097-why-spring-batch-doesn-t-support-informix-database,您似乎可以将数据库类型设置为Oracle,它将支持Informix。