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

线程“main”组织中出现异常。springframework。豆。工厂UnsatifiedPendencyException:创建名为的bean时出错

卫焕
2023-03-14

我正在使用带有Boot的Spring Batch并使用XML配置来配置批处理作业。但是批处理作业是使用Tivoli调度的。同样,我希望通过使用批处理启动器进行配置来在本地运行。

我们怎样才能满足依赖性?

Exception in thread "main" org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'panAccountRangeDao' defined in file [C:\Project\Core\src\main\resources\META-INF\spring\XXX-batch-job.xml]: Unsatisfied dependency expressed through constructor parameter 0: Ambiguous argument values for parameter of type [javax.sql.DataSource] - did you specify the correct bean references as arguments?
    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:736)
    at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:189)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1143)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1046)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:776)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:861)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541)
    at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:140)
    at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:94)
    at com.mastercard.ess.eds.CustomerFileGenerationApp.main(CustomerFileGenerationApp.java:29)

当我配置JobLauncher时

<bean id="transactionManager" class="org.springframework.batch.support.transaction.ResourcelessTransactionManager" />

<bean id="jobRepository" class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean" >
    <property name="dataSource" ref="ABCDataSource" />
    <property name="transactionManager" ref="transactionManager" />
    <property name="databaseType" value="Oracle" />
</bean>

<bean id="jobLauncher" class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
    <property name="jobRepository" ref="jobRepository" />
</bean>

Database aseConfig.java

@Configuration
@Component
@PropertySource("classpath:database.properties")
public class DatabaseConfig {
    private static Logger logger = Logger.getLogger(DatabaseConfig.class);

    @Value("${jdbc.url}")
    private String edsurl;

    @Value("${jdbc.driverClassName}")
    private String className;

    @Bean(name = "ABCDataSource")
    public DataSource batchABCDataSource() throws IOException {

        logger.info("Enter into BatchABCDataSource method");

        OracleDataSource ds = null;
        MCUserInfoFactory userInfoFactory = new MCUserInfoFactory();
        try {
            MCUserInfo userInfo = userInfoFactory.getMCUserInfo(XXLabel);
            if (userInfo != null) {
                ds = getDataSource(userInfo, XXXurl);
            }

        } catch (Exception e) {
            logger.error("Exception occured while initializing the EDS datatsource" + e);
            throw new IOException("Exception occured while initializing the EDS datatsource", e);
        }

        logger.info("Exit into BatchABCDataSource method");

        return ds;
    }


    private OracleDataSource getDataSource(MCUserInfo userInfo , String url) throws SQLException {
        OracleDataSource ds = new OracleDataSource();
        ds.setURL(url);
        ds.setUser(userInfo.getUserid());
        ds.setPassword(userInfo.getPassword());
        Properties properties = new Properties();
        properties.setProperty(MIN_LIMIT, minPoolSize.toString());
        properties.setProperty(MAX_LIMIT, maxPoolSize.toString());
        ds.setConnectionCacheProperties(properties);
        return ds;
    }
}

XML配置:

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:batch="http://www.springframework.org/schema/batch" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:task="http://www.springframework.org/schema/task" xmlns:util="http://www.springframework.org/schema/util"
    xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/task  http://www.springframework.org/schema/task/spring-task.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">

    <batch:job id="ABCProcessJob">
        <batch:step id="abcDataInCache">
            <batch:tasklet ref = "cacheLoader" />
            <batch:next on="COMPLETED" to="ABCStep"/>
            <batch:fail on="FAILED" exit-code="XXXXXXX" /> 
        </batch:step>
        <batch:step id="ABCStep">
            <partition partitioner="abcPartitioner" handler="ABCProcessHandler">
            </partition>
        </batch:step>
    </batch:job>

    <bean id="ABCProcessHandler" class="org.springframework.batch.core.partition.support.TaskExecutorPartitionHandler" scope="step">
        <property name="taskExecutor" ref="ABCTaskExecutor" />
        <property name="step" ref="processBatch" />
        <property name="gridSize" value="20" />
    </bean>

    <batch:step id="processBatch">  
        <batch:tasklet>
            <batch:chunk reader="ABCRecordItemReader" writer="abcRecordDBWriter"
                processor="panProcessor" commit-interval="100" skip-limit="60000" processor-transactional="false">
                <batch:skippable-exception-classes>
                    <batch:include class="org.springframework.batch.item.validator.ValidationException" />
                    <batch:include class="com.XXXX.abcException" />
                </batch:skippable-exception-classes>
                <batch:listeners>
                    <batch:listener>
                        <bean class="com.XXXXXXXXXXX.listener.RawRecordSkipListener" scope="step">
                            <property name="jobInstanceName" value="#{stepExecution.jobExecution.jobInstance.jobName}"/>
                            <property name="jobInstanceId" value="#{stepExecution.jobExecution.jobId}"/>
                        </bean>
                    </batch:listener>
                </batch:listeners>
            </batch:chunk>
        </batch:tasklet>
    </batch:step>
</beans>

共有1个答案

蒋英博
2023-03-14

正如stack trace中提到的,我认为您需要仔细检查panAccountRangeDao的构造函数。他们有没有第一个参数javax。sql。数据源类型?

 类似资料: