1

Could someone please take a look at this code and help me find out what is causing the error: 'beanName must not be empty.

I'm using Spring Tool Suite 3.3.0.

I am trying to write a small spring-batch job that does not persist the job stats or anything. I just want to use spring framework. This is not the entire job, but I'm having trouble getting past this problem.

This is my simple job with one step. Where is the empty bean??

My spring-batch code:

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

if it matters, here's my tasklet class

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

}
4

1 回答 1

1

我开始调试 spring-batch 代码以查找其中的 bean 检查失败的地方。我注意到调试步进器并没有在实际执行的代码上停止。这让我觉得我遇到了类路径和 jar 问题。所以,我查看了我的 maven 依赖项,看看我使用的是什么版本。我的好批处理项目使用的是 Spring jars 3.2.2,而我失败的项目是 3.0.6。那是我的第一个线索。这不对!

所以我通过将 pom.xml 更改为 3.2.2 来解决这个问题。然后,在那之后,我意识到我失败的项目中还有另一个版本不匹配的 jar 以及我手动添加的。我删除了它,让行星对齐,一切都很好。

项目向导如何选择两个不同版本的 spring 框架是一个问题,但经过几天的挫折,我很高兴看到它工作。

感谢所有查看此问题的人。

于 2013-09-09T15:22:38.437 回答