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

使用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();
    }
}

你可能感兴趣的:(问题)