Question

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

}
Was it helpful?

Solution

I started to debug the spring-batch code to find where in it there was a bean check that was failing. I noticed that the debug stepper wasn't stopping on actual executing code. That made me think I had the classpath and jar issues. So, I looked at my maven dependencies to see what version I was using. My Good batch project was using Spring jars 3.2.2 and my failing project was 3.0.6. That was my first clue. This ain't right!

So I fixed that by changing the pom.xml to be 3.2.2. Then, after that I realized my failing project had another version-mismatched jar in it as well that I had manually added. I removed it, got the planets aligned and all is well.

How the project wizard chose two different versions of spring framework is a question, but after several days of frustration, I was just happy to see it work.

Thanks to all who viewed this question.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top