I am writing a component using Spring Boot and Spring Boot JPA. I have a setting like this:
Interface:
public interface Something {
}
Implementation:
@Component
public class SomethingImpl implements Something {
}
Now I have a JUnit test that works with SpringJUnit4ClassRunner, and I want to test mine SomethingImplwith this.
When i do
@Autowired
private Something _something;
it works but
@Autowired
private SomethingImpl _something;
makes the test discard NoSuchBeanDefinitionExceptionwith a messageNo qualifying bean of type [com.example.SomethingImpl] 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)}
But in the test case, I want to explicitly enter mine SomethingImpl, because this is the class I want to test. How to achieve this?
source
share