@Autowired - No qualifying bean of type found for dependency

前端 未结 17 1575
自闭症患者
自闭症患者 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:24

    Instead of @Autowire MailManager mailManager, you can mock the bean as given below:

    import org.springframework.boot.test.mock.mockito.MockBean;
    
    ::
    ::
    
    @MockBean MailManager mailManager;
    

    Also, you can configure @MockBean MailManager mailManager; separately in the @SpringBootConfiguration class and initialize like below:

    @Autowire MailManager mailManager
    

提交回复
热议问题