线程“主”中的异常org.springframework.beans.factory.UnsatisfiedDependencyException:创建名称为bean的错误

时间:2018-07-03 16:26:17

标签: spring spring-boot spring-batch

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

我们如何满足这种依赖性?

root      1885  0.0  0.1 232060  3832 ?        Sl   Jul02   0:00 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 2600 -container-ip 172.20.0.2 -container-port 80

当我配置JobLauncher

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)

DatabaseConfig.java

<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>

XML配置:

@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;
    }
}

1 个答案:

答案 0 :(得分:0)

如堆栈跟踪中所述,我认为您需要仔细检查panAccountRangeDao的构造函数。 他们有第一个参数是javax.sql.DataSource类型吗?