No qualifying bean of type [org.springframework.web.context.WebApplicationContext]

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/m0_37681914/article/details/80614195

使用Junit结合mock做单元测试遇到的问题。原因缺少@WebAppConfiguration

@ContextConfiguration(locations = {"classpath:/testContext.xml"})
@RunWith(SpringJUnit4ClassRunner.class)
//加上 @WebAppConfiguration
@WebAppConfiguration
public class UserMarketingActivityControllerTest {

    @Resource
    private UserMarketingActivityController userMarketingActivityController;

    @Resource
    private WebApplicationContext wac;

    private MockMvc mockMvc;

    @Before
    public void setUp() throws Exception {
        mockMvc = MockMvcBuilders.webAppContextSetup(wac).build();
    }
}

猜你喜欢

转载自blog.csdn.net/m0_37681914/article/details/80614195