Issue with SpringJunit4ClassRunner and autowiring of dependencies..
Hello,
I am running into problems trying to test a Spring batch application. Here is what I get:
Code:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.jeanbaptistemartin.batch.mailing.AppTest': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.batch.test.JobLauncherTestUtils com.jeanbaptistemartin.batch.mailing.AppTest.jobLauncherTestUtils; nested exception is 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), @org.springframework.beans.factory.annotation.Qualifier(value=jobLauncherTestUtils)}
Here is my test class:
Code:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations="file:./test-context.xml")
public class AppTest {
@Autowired
private JobLauncherTestUtils jobLauncherTestUtils;//this does not get autowired
@Test
@DirtiesContext
public void integration() throws Exception{
JobParameters jobParameters = new JobParametersBuilder().addString("date","2012/01/04").toJobParameters();
JobExecution exec = jobLauncherTestUtils.launchJob(jobParameters);
}
}
and the application context config class:
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"
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">
<context:annotation-config/>
<context:component-scan base-package="org.springframework.batch"/>
<import resource="classpath:root-batch-mailing.xml" />
</beans>