Announcement Announcement Module
Collapse
No announcement yet.
Error JobRepository is mandatory Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Error JobRepository is mandatory

    Peoples.

    When I start my job I get the error below (Caused by: java.lang.IllegalArgumentException: JobRepository is mandatory).
    Follow my files of application below to.
    Someone had an idea of how to bypass or solve this problem?

    Error
    Code:
    Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requesterElectronicInvoice': Cannot create inner bean '(inner bean)' of type [org.springframework.batch.core.job.flow.support.SimpleFlow] while setting bean property 'flow'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)': Cannot create inner bean '(inner bean)' of type [org.springframework.batch.core.job.flow.support.StateTransition] while setting bean property 'stateTransitions' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)': Cannot create inner bean '(inner bean)' of type [org.springframework.batch.core.job.flow.support.state.StepState] while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)': Cannot resolve reference to bean 'step1' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'step1': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalArgumentException: JobRepository is mandatory
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:230)
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:122)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1245)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
    	at br.com.moip.initializer.ApplicationContextFactoryJob.getBean(ApplicationContextFactoryJob.java:66)
    	at br.com.moip.initializer.ApplicationContextFactoryJob.main(ApplicationContextFactoryJob.java:80)
    Job
    Code:
     <beans:beans xmlns="http://www.springframework.org/schema/batch" 
         xmlns:beans="http://www.springframework.org/schema/beans" 
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="
               http://www.springframework.org/schema/beans 
               http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
               http://www.springframework.org/schema/batch 
               http://www.springframework.org/schema/batch/spring-batch-2.0.xsd">
    
    	<job id="requesterElectronicInvoice" job-repository="jobRepository">
    		<step id="step1">
    			<tasklet transaction-manager="transactionManager">
    				<chunk reader="hibernateItemReader"  processor="ProcessorRps"  writer="itemWriter" commit-interval="10" />
    			</tasklet>
    		</step>
    	</job>
    
    	<beans:bean id="ReaderInvoice" class="br.com.moip.jobs.rnf.ReaderInvoice">
    		<beans:property name="sessionFactory" ref="sessionFactory" />
    	</beans:bean>
    
    	<beans:bean id="hibernateItemReader"
    			class="org.springframework.batch.item.database.HibernateCursorItemReader">		
    		<beans:property name="queryString" value="from PaymentUsed where status = 1"/>
    		<beans:property name="sessionFactory" ref="sessionFactory" />
    	</beans:bean>
    	
    	<beans:bean id="ProcessorRps" class="br.com.moip.jobs.rnf.ProcessorInvoice"/>
    	
    	<beans:bean id="itemWriter"
    		class="br.com.moip.jobs.rnf.WriterInvoice">
    			<beans:property name="sessionFactory" ref="sessionFactory" />		
    	</beans:bean>
    	
    		
    
    </beans:beans>
    Launcher
    Code:
    ]
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
    	xmlns:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="
    		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
    		http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
    		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
    	
    	<bean id="jobRepository"
    		class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean">
    		<property name="dataSource" ref="dataSource"/>
    		<property name="transactionManager" ref="transactionManager"/>
    	 </bean>
    		
    
    	<bean id="jobLauncher"
    		class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
    		<property name="jobRepository" ref="jobRepository" />
    	</bean>
    
    	<bean class="org.springframework.batch.core.configuration.support.JobRegistryBeanPostProcessor">
    		<property name="jobRegistry" ref="jobRegistry"/>
    	</bean>
    	
    	<bean id="mapJobRepository"
    		class="org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean"
    		lazy-init="true" autowire-candidate="false" />
    
    	<bean id="jobOperator"
    		class="org.springframework.batch.core.launch.support.SimpleJobOperator"
    		p:jobLauncher-ref="jobLauncher" p:jobExplorer-ref="jobExplorer"
    		p:jobRepository-ref="jobRepository" p:jobRegistry-ref="jobRegistry" />
    
    	<bean id="jobExplorer"
    		class="org.springframework.batch.core.explore.support.JobExplorerFactoryBean"
    		p:dataSource-ref="dataSource" />
    
    	<bean id="jobRegistry"
    		class="org.springframework.batch.core.configuration.support.MapJobRegistry" />	
    </beans>
    Main Class
    Code:
    public class ApplicationContextFactoryJob implements InitializingBean {
    
    	static Logger logger = Logger.getLogger(ApplicationContextFactoryJob.class);
    
    	PaymentUsed paymentUsed;
    
    	protected static ApplicationContextFactoryJob instance = new ApplicationContextFactoryJob();
    	private BeanFactory factory;
    	ConsoleAppender consoleAppender = new ConsoleAppender(new PatternLayout());
    
    	private ApplicationContextFactoryJob() {
    		Resource resource = new ClassPathResource("applicationContext.xml");
    		factory = new XmlBeanFactory(resource);		
    	}
    
    	public Object getBean(String id) {
    		return factory.getBean(id);
    	}
    
    	public static void main(String args[])
    			throws JobExecutionAlreadyRunningException, JobRestartException,
    			JobInstanceAlreadyCompleteException {
    //		try {
    //			instance.getBean("PaymentUsed");
    //			logger.info("transactionManager carregado com sucesso");
    //		} catch (Exception e) {
    //			throw new BeanInitializationException(
    //					"transactionManager Bean can not be created", e);
    //		}
    		HibernateTransactionManager transactionManager = (HibernateTransactionManager)instance.getBean("transactionManager");
    		Job rfn = (Job) instance.getBean("requesterElectronicInvoice");
    		JobLauncher launcher = (JobLauncher) instance.getBean("jobLauncher");		
    		JobParameters jobParameters = null;
    		JobExecution jobExecution = launcher.run(rfn, jobParameters);
    
    	}
    
    	public void afterPropertiesSet() throws Exception {
    		Assert.notNull(paymentUsed);
    	}
    }
Working...
X