I am new to spring boot and I am writing Junit for my REST Api.so many annotation are required by my class to run Junit. So I planned to put all annotation in one custom annotation and use that custom annotation in my Junit class. But now my Autowire is stopped working.
I tried to create custom annotation and used that in my Junit class but now @Autowire annotation has stopped to work.
Below is code of custom annotation:
@Inherited
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.CLASS)
@Documented
@Category(UnitTest.class)
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = {AptDataApiApplicationRepo.class })
@TestPropertySource("classpath:application-test.properties")
public @interface RepoTestConfig {
}
// My JUnit class code
@RepoTestConfig
public class HolidayRepoTest {
@Autowired
private IHolidayRepo iHolidayRepo;
}
// here spring throwing an exception when spring context is trying to get up
Exception coming is :
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.demo.repository.IHolidayRepo' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
@Note: When I am putting all annotation in HolidayRepoTest class then every thing is fine.