2013-06-29 8 views
6

में AutLired JobLauncherTestUtils को स्वचालित नहीं किया जा सका-बैच में एक चरण के लिए एक कार्यात्मक परीक्षण करते समय मुझे त्रुटि मिल रही है। त्रुटि नीचे हो रही है:स्प्रिंग-बैच

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [org.springframework.batch.test.JobLauncherTestUtils] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} 
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:924) 
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:793) 
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:707) 
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:478) 

नीचे इस के लिए इस्तेमाल किया विन्यास फाइल और टेस्ट फ़ाइल है।

कस्टम context.xml फ़ाइल:

<batch:job id="custom.entities"> 
    <batch:step id="entity.processor"> 
     <batch:tasklet> 
      <batch:chunk reader="customReader" writer="customWriter" commit-interval="1" /> 
     </batch:tasklet> 
    </batch:step> 
</batch:job> 

<bean id="customReader" class="com.batch.custom.EntityReader" scope="step"> 
    <property name="providerId" value="#{jobParameters['providerId']}" /> 
</bean> 

<bean id="customWriter" class="org.springframework.batch.item.file.FlatFileItemWriter"> 
    <property name="resource" value="file:c:/Temp/ledgers-output.txt"/> 
    <property name="lineAggregator"> 
     <bean class="org.springframework.batch.item.file.transform.PassThroughLineAggregator" /> 
    </property> 
</bean> 

CustomJobTest.java फ़ाइल

@Autowired 
private JobLauncherTestUtils jobLauncherTestUtils; 

@Autowired 
private ItemReader<WatchlistDataSet> reader; 

@Test 
@DirtiesContext 
public void testLaunchJob() throws Exception { 

    JobParameters jobParameters = new JobParametersBuilder().addString("providerId", "cnp_1").toJobParameters(); 

    JobExecution exec = jobLauncherTestUtils.launchStep("entity.processor", jobParameters); 

    assertEquals(BatchStatus.COMPLETED, exec.getStatus()); 

} 

public JobLauncherTestUtils getJobLauncherTestUtils() { 
    return jobLauncherTestUtils; 
} 

public void setJobLauncherTestUtils(JobLauncherTestUtils jobLauncherTestUtils) { 
    this.jobLauncherTestUtils = jobLauncherTestUtils; 
} 

उत्तर

14

कुछ Googling के बाद पता चला कि एक सेम परिभाषा JUnit के लिए इस्तेमाल किया context.xml में निर्दिष्ट करने की आवश्यकता है परिक्षण।

<bean id="jobLauncherTestUtils" class="org.springframework.batch.test.JobLauncherTestUtils" > 
    <property name="job" ref="custom.entities"/> 
    <property name="jobRepository" ref="jobRepository"/> 
    <property name="jobLauncher" ref="jobLauncher"/> 
</bean> 

उपर्युक्त परिभाषा के साथ मैं जॉबलाउचरटेस्टयूट्स को स्वत: करने में सक्षम हूं।