有人可以看看这段代码并帮我找出导致错误的原因:'beanName不能为空。
我正在使用Spring Tool Suite 3.3.0。
我正在尝试编写一个小型的弹簧批作业,它不会保留作业统计信息或其他任何内容。我只是想使用spring框架。这不是整个工作,但我遇到了解决这个问题的麻烦。
这是我一步到位的简单工作。空豆在哪里??
我的春季批次代码:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:batch="http://www.springframework.org/schema/batch"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xsi:schemaLocation="
http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.1.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:property-placeholder location="classpath:batch.properties" />
<context:component-scan base-package="com.mycompany.batch" />
<bean id="transactionManager"
class="org.springframework.batch.support.transaction.ResourcelessTransactionManager" />
<bean id="jobRepository"
class="org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean">
<property name="transactionManager" ref="transactionManager" />
</bean>
<bean id="jobLauncher"
class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
<property name="jobRepository" ref="jobRepository" />
</bean>
<!-- <import resource="classpath:/META-INF/spring/module-context.xml" /> -->
<batch:job id="vendorGoalsJob" restartable="true">
<batch:step id="checkStartFileExists">
<batch:tasklet ref="startFileExistsTasklet" />
</batch:step>
</batch:job>
<bean id="startFileExistsTasklet"
class="com.mycompany.batch.domain.vendor.goal.StartFileExistsTasklet">
<property name="path" value="${filepath}" />
<property name="file" value="${filename}" />
</bean>
</beans>
2013-09-06 10:12:56,214 INFO [org.springframework.context.support.ClassPathXmlApplicationContext] - <Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@67ac19: startup date [Fri Sep 06 10:12:56 CDT 2013]; root of context hierarchy>
2013-09-06 10:12:56,261 INFO [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - <Loading XML bean definitions from class path resource [launch-context.xml]>
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [launch-context.xml]; nested exception is java.lang.IllegalArgumentException: 'beanName' must not be empty
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:412)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:212)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:126)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:92)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:130)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:467)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:397)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at com.glazers.batch.domain.vendor.goal.VendorGoalLauncher.doit(VendorGoalLauncher.java:39)
at com.glazers.batch.domain.vendor.goal.VendorGoalLauncher.main(VendorGoalLauncher.java:32)
Caused by: java.lang.IllegalArgumentException: 'beanName' must not be empty
at org.springframework.util.Assert.hasText(Assert.java:162)
at org.springframework.beans.factory.config.RuntimeBeanReference.<init>(RuntimeBeanReference.java:58)
at org.springframework.beans.factory.config.RuntimeBeanReference.<init>(RuntimeBeanReference.java:46)
at org.springframework.batch.core.configuration.xml.AbstractStepParser.setUpBeanDefinitionForTaskletStep(AbstractStepParser.java:155)
at org.springframework.batch.core.configuration.xml.AbstractStepParser.parseTasklet(AbstractStepParser.java:133)
at org.springframework.batch.core.configuration.xml.AbstractStepParser.parseStep(AbstractStepParser.java:85)
at org.springframework.batch.core.configuration.xml.InlineStepParser.parse(InlineStepParser.java:59)
at org.springframework.batch.core.configuration.xml.FlowParser.doParse(FlowParser.java:119)
at org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser.parseInternal(AbstractSingleBeanDefinitionParser.java:85)
at org.springframework.beans.factory.xml.AbstractBeanDefinitionParser.parse(AbstractBeanDefinitionParser.java:59)
at org.springframework.batch.core.configuration.xml.JobParser.doParse(JobParser.java:95)
at org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser.parseInternal(AbstractSingleBeanDefinitionParser.java:85)
at org.springframework.beans.factory.xml.AbstractBeanDefinitionParser.parse(AbstractBeanDefinitionParser.java:59)
at org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:73)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1338)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1328)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:135)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:93)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:493)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:390)
... 15 more
如果重要,这是我的tasklet类
package com.mycompany.batch.domain.vendor.goal;
import java.io.File;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.repeat.RepeatStatus;
public class StartFileExistsTasklet implements Tasklet {
private String path;
private String file;
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
StringBuffer sb = new StringBuffer();
sb.append(path.trim()).append(File.pathSeparator).append(file.trim());
File f = new File(sb.toString());
if (f.isFile())
chunkContext.getStepContext().getStepExecution().setTerminateOnly();
return RepeatStatus.FINISHED;
}
public void setPath(String path) {
this.path = path;
}
public void setFile(String file) {
this.file = file;
}
}
答案 0 :(得分:1)
我开始调试spring-batch代码,找到其中有一个失败的bean检查。我注意到调试步进器没有停止实际执行代码。这让我觉得我有类路径和jar问题。所以,我查看了我的maven依赖项,看看我使用的是什么版本。我的Good批处理项目使用Spring jar 3.2.2,我的失败项目是3.0.6。这是我的第一个线索。这不对!
所以我通过将pom.xml更改为3.2.2来解决这个问题。然后,在那之后,我意识到我的失败项目中还有另一个版本不匹配的jar,我手动添加了。我把它移走了,让行星对齐,一切都很好。
项目向导如何选择两个不同版本的spring框架是一个问题,但经过几天的挫折之后,我很高兴看到它的工作。
感谢所有看过这个问题的人。