当前位置: 首页 > 知识库问答 >
问题:

Spring批处理---找不到产品名称的数据库类型:[Informix动态服务器]

宓博实
2023-03-14

我想用Spring boot实现Spring批处理,因为我们使用的是informix数据库,所以当我的Spring boot应用程序启动时,我遇到了以下异常。

配置:

@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:在组织中找不到产品名称:[Informix动态服务器]的DatabaseType。springframework。一批支持数据库类型。位于org的fromProductName(DatabaseType.java:79)。springframework。一批支持数据库类型。org上的fromMetaData(DatabaseType.java:110)。springframework。靴子自动配置。一批BatchDatabaseInitializer。位于org的getDatabaseType(BatchDatabaseInitializer.java:71)。springframework。靴子自动配置。一批BatchDatabaseInitializer。在sun上初始化(BatchDatabaseInitializer.java:50)。反映NativeMethodAccessorImpl。在sun调用0(本机方法)。反映NativeMethodAccessorImpl。在sun上调用(NativeMethodAccessorImpl.java:62)。反映DelegatingMethodAccessorImpl。在java上调用(DelegatingMethodAccessorImpl.java:43)。lang.reflect。方法在org调用(Method.java:497)。springframework。豆。工厂注释。InitDestroyAnnotationBeanPostProcessor$LifecycleElement。在组织中调用(InitDestroyAnnotationBeanPostProcessor.java:349)。springframework。豆。工厂注释。InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata。org上的invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:300)。springframework。豆。工厂注释。InitDestroyAnnotationBeanPostProcessor。初始化前的后处理(InitDestroyAnnotationBeanPostProcessor.java:133)

共有1个答案

华谭三
2023-03-14

Spring批处理似乎并不直接支持Informix。

org.springframework.batch.support.数据库类型

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。

 类似资料: