I would like to inject a Mockito mock object into a Spring (3+) bean for the purposes of unit testing with JUnit. My bean dependencies are currently injected by using the
If you're using spring >= 3.0, try using Springs @Configuration annotation to define part of the application context
@Configuration
@ImportResource("com/blah/blurk/rest-of-config.xml")
public class DaoTestConfiguration {
@Bean
public ApplicationService applicationService() {
return mock(ApplicationService.class);
}
}
If you don't want to use the @ImportResource, it can be done the other way around too:
For more information, have a look at spring-framework-reference : Java-based container configuration