我正在使用带有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>
正如stack trace中提到的,我认为您需要仔细检查panAccountRangeDao
的构造函数。他们有没有第一个参数是javax。sql。数据源
类型?
我得到以下错误消息,而运行我的项目 组织。springframework。豆。工厂UnsatisfiedPendencyException:创建名为“TipoeStatDoCivilController”的bean时出错:通过字段“TipoeStatDoCivilService”表示的未满足的依赖关系;嵌套的异常是org。springframework。豆。工厂UnsatisfiedPendenc
我正在做项目的Spring启动...但是得到了这个错误,而运行应用程序。这可能是H2数据库错误。但是要解决这个错误localhost应该运行,但程序在部署前终止...所以我不能看到什么是实际问题。 错误:org.springframework.beans.factory.BeanCreationException:创建名称为'project TaskRepository'的bean时出错com.a
我正在尝试运行以下代码 我的配置类是: AppConfig.class RepositoryConfig.class 我的模型课是:POC。班 我的存储库类是:POCRepository类 我的服务等级是: 我正在运行main类,出现以下错误。 我的网络。xml详细信息如下 请帮帮我
我有一个数据库配置类来连接我的Spring网络服务和数据库。我正在使用Spring引导,使它成为独立的应用程序。 这是我的课 每次我尝试运行我的代码,它都会抛出异常: 据我所知,有一个缺失的依赖项,但我不知道是哪个。或者问题是别的什么?这是我在pom.xml的依赖项 你知道问题的原因和解决方法吗?
我有一个Spring启动应用程序。我用@Component注释了项目的一个类。现在在我的主类中,当我试图获取该类的bean时,我得到一个异常,它无法找到该bean。 注释为组件的类如下
你好,我正在尝试按照本教程在我的项目中实现Spring Securityhttp://www.baeldung.com/2011/10/31/securing-a-restful-web-service-with-spring-security-3-1-part-3/#config,在运行我的程序时,我遇到了以下异常- org.springframework.beans.factory。BeanC