Announcement Announcement Module
Collapse
No announcement yet.
How to instantiate MapJobExplorerFactoryBean Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

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

    Comment


    • #3
      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.

      Comment


      • #4
        Originally posted by snicoll View Post

        uh? No, you don't.
        Resurrecting a dead post here...

        In this specific case, you actually do have to add the ampersand because the MapJobExplorerFactoryBean's repositoryFactory property wants a MapJobRepositoryFactoryBean, not a JobRepository.

        Comment

        Working...
        X