没有定义名为'springbatch.readerDataSource'的bean

在执行我的工作时,我遇到了异常

设置bean属性'dataSource'时无法解析对bean'springbatch.readerDataSource'的引用;嵌套异常是org.springframework.beans.factory.NoSuchBeanDefinitionException:没有名为'springbatch.readerDataSource'的bean在org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:329)中定义

注意 - 我没有创建单独的阅读器文件 . 使用JdbcCursorItemReader .

My configuration file

<bean id="itemReader" 
        class="org.springframework.batch.item.database.JdbcCursorItemReader" scope="step">
        <property name="dataSource" ref="springbatch.batchDataSource"/>
        <property name="sql"  
                  value=
                    "select Cust_Id  from Customer   "/>
        <property name="rowMapper">
            <bean class="com.insurance.premiumrecalculation.batch.CustDto" />
         </property>
    </bean>

    <bean id="policy.premium.recalculation.PremiumRecalculationWriter" 
        class="com.insurance.premiumrecalculation.batch.PremiumRecalculationProcessWriter" scope="step"/>

    <batch:job id="policy.job.premiumRecalculation" 
        job-repository="springbatch.jobRepository" parent="springbatch.job.baseJob">

        <batch:step id="policy.step.premiumrecalculation" parent="springbatch.step.baseStep">
            <batch:tasklet allow-start-if-complete="false" transaction-manager="powTransactionManager">                                   
                <batch:chunk commit-interval="10"                    
                    reader="itemReader"
                    writer="policy.premium.recalculation.PremiumRecalculationWriter"/>                    
            </batch:tasklet>
        </batch:step>
    </batch:job>

提前致谢

回答(1)

2 years ago

此错误的来源如下:

<property name="dataSource" ref="springbatch.batchDataSource"/>

这意味着你需要一个id为“springbatch.batchDataSource”的bean定义,它被配置为你的环境似乎不存在的数据源 . 您可以使用以下作为模板;不要忘记提供您的数据库驱动程序和连接信息 .

<bean id="springbatch.batchDataSource" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName" value="org.hsqldb.jdbcDriver" />
    <property name="url" value="jdbc:hsqldb:mem:testdb" />
    <property name="username" value="sa" />
    <property name="password" value="" />
</bean>