Results 1 to 3 of 3

Thread: How to instantiate MapJobExplorerFactoryBean

  1. #1
    Join Date
    Apr 2010
    Posts
    5

    Default How to instantiate MapJobExplorerFactoryBean

    I've started using Spring Batch 2.1 but I'm having a problem when trying to add a MapJobExplorerFactoryBean to my application context. Here is my configuration via XML:

    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:context="http://www.springframework.org/schema/context"
    	xmlns:batch="http://www.springframework.org/schema/batch"
    	xsi:schemaLocation="
    		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
    		http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.1.xsd">
    
    	<!-- use for production with database: JobExplorerFactoryBean -->
    	<bean id="jobExplorer" class="org.springframework.batch.core.explore.support.MapJobExplorerFactoryBean">
    		<property name="repositoryFactory" ref="jobRepository" />
    	</bean>
    	
    	<!-- In memory job repository for testing -->
    	<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>
    	
    	<bean id="jobRegistry" class="org.springframework.batch.core.configuration.support.MapJobRegistry" />
    	<!-- Add a register post-processor to automatically register all jobs as they're created -->
    	<bean id="jobRegistryBeanPostProcessor" class="org.springframework.batch.core.configuration.support.JobRegistryBeanPostProcessor">
        <property name="jobRegistry" ref="jobRegistry"/>
    	</bean>
    	
    	<bean id="jobOperator" class="org.springframework.batch.core.launch.support.SimpleJobOperator">
        <property name="jobExplorer" ref="jobExplorer" />
        <property name="jobRepository" ref="jobRepository" />
        <property name="jobRegistry" ref="jobRegistry" />
        <property name="jobLauncher" ref="jobLauncher" />		
    	</bean>
    
    	<bean id="sampleTasklet" class="com.myorg.task.ExampleTask" />
    
    	<batch:job id="sampleJob">
    		<batch:step id="step0">
    			<batch:tasklet ref="sampleTasklet" />
    		</batch:step>
    	</batch:job>
    	
    
    </beans>
    As my application starts, I receive the following exception:
    Code:
    Caused by: java.lang.IllegalStateException: Cannot convert value of type [$Proxy25 implementing org.springframework.batch.core.repository.JobRepository,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean] for property 'repositoryFactory': no matching editors or conversion strategy found
    I don't understand how to create a MapJobExplorerFactoryBean in XML. I think I'm missing something about how a JobRepository and MapJobExplorerFactoryBean are related. Any help is appreciated. Thanks,

    Andrew

    (And yes, I would like to get this working in memory before I put a real database behind it)

  2. #2
    Join Date
    Apr 2010
    Posts
    5

    Default Solution Found

    Found the solution...

    Since I'm relatively new to spring, I didn't realize the correct way to pass a factory around. I needed to put an ampersand '&' in front of my 'ref' decleration. However, I got an XML parse exception when I tried to do that, so I had to escape the ampersand: & ---> &amp;

    My correct configuration file looks like:

    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:context="http://www.springframework.org/schema/context"
    	xmlns:batch="http://www.springframework.org/schema/batch"
    	xsi:schemaLocation="
    		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
    		http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.1.xsd">
    
    	<!-- use for production with database: JobExplorerFactoryBean -->
    	<bean id="jobExplorer" class="org.springframework.batch.core.explore.support.MapJobExplorerFactoryBean">
    		<property name="repositoryFactory" ref="&amp;jobRepository" />
    	</bean>
    	
    	<!-- In memory job repository for testing -->
    	<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>
    	
    	<bean id="jobRegistry" class="org.springframework.batch.core.configuration.support.MapJobRegistry" />
    	<!-- Add a register post-processor to automatically register all jobs as they're created -->
    	<bean id="jobRegistryBeanPostProcessor" class="org.springframework.batch.core.configuration.support.JobRegistryBeanPostProcessor">
        <property name="jobRegistry" ref="jobRegistry"/>
    	</bean>
    	
    	<bean id="jobOperator" class="org.springframework.batch.core.launch.support.SimpleJobOperator">
        <property name="jobExplorer" ref="jobExplorer" />
        <property name="jobRepository" ref="jobRepository" />
        <property name="jobRegistry" ref="jobRegistry" />
        <property name="jobLauncher" ref="jobLauncher" />		
    	</bean>
    
    	<bean id="sampleTasklet" class="com.myorg.task.ExampleTask" />
    
    	<batch:job id="sampleJob">
    		<batch:step id="step0">
    			<batch:tasklet ref="sampleTasklet" />
    		</batch:step>
    	</batch:job>
    	
    
    </beans>
    
    
    
    I guess this was more of a Spring question than a Spring Batch questions.  Hopefully this helps someone else.
    
    Andrew

  3. #3

    Default

    Quote Originally Posted by anschoewe View Post
    Found the solution...

    Since I'm relatively new to spring, I didn't realize the correct way to pass a factory around. I needed to put an ampersand '&' in front of my 'ref' decleration.
    uh? No, you don't.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •