SpringMVC JUnit总是报404 ,加载拦截器不是我自定义的

取个昵称咋这么难啊 发布于 2017/02/28 18:27
阅读 541
收藏 0

代码:

@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration(locations = { "classpath*:applicationContext.xml", "classpath:spring-mvc.xml"})
public class FetalControllerTest {
    @Autowired
    private WebApplicationContext wac;

    private MockMvc mockMvc;

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

    @Test
    public void getAll() throws Exception {
        System.out.println();
        ResultActions resultActions = this.mockMvc.perform(MockMvcRequestBuilders.get("/obcism/obsNewBorn/getAll"));
        MvcResult mvcResult = resultActions.andReturn();
        System.out.println("----mvcResult :\t" + mvcResult.getResponse().getStatus());
        System.out.println("----reponse :\t" + mvcResult.getResponse());
    }

}

 

结果:

No mapping found for HTTP request with URI [/obcism/obsNewBorn/getAll] in DispatcherServlet with name ''

 

拦截器定义:

<!-- 加载SpringMVC Servlet -->
    <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath*:spring-mvc.xml</param-value>
        </init-param>
        <!-- 该Servlet自动加载 -->
        <load-on-startup>1</load-on-startup>
    </servlet>
    <!-- 拦截所有的路径 -->
    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

加载中
返回顶部
顶部