@Autowired - No qualifying bean of type found for dependency

前端 未结 17 1532
自闭症患者
自闭症患者 2020-12-07 15:00

I\'ve started my project by creating entities, services and JUnit tests for services using Spring and Hibernate. All of this works great. Then I\'ve added spring-mvc to make

17条回答
  •  北海茫月
    2020-12-07 15:36

    The solution that worked for me was to add all the relevant classes to the @ContextConfiguration annotation for the testing class.

    The class to test, MyClass.java, had two autowired components: AutowireA and AutowireB. Here is my fix.

    @ContextConfiguration(classes = {MyClass.class, AutowireA.class, AutowireB.class})
    public class MyClassTest {
    ...
    }
    

提交回复
热议问题