Spring MVC:警告:没有找到带URI的HTTP请求的映射

时间:2016-12-09 13:10:32

标签: java spring spring-mvc

我的Spring Web模型 - 视图 - 控制器(MVC)框架中有这个类。 Spring Web模型 - 视图 - 控制器(MVC)框架的版本是3.2.8。

我有这个web.xml文件。

...
<servlet-mapping>
                <servlet-name>ecolabelWeb</servlet-name>
                <url-pattern>*.do</url-pattern>

                <url-pattern>/newdesign/manage/manageapplications</url-pattern>    
                <url-pattern>/newdesign/manage/manageapplications/</url-pattern>
                <url-pattern>/newdesign/manage/manageapplications/*</url-pattern>

                <url-pattern>/newdesign/manage/home</url-pattern>    
                <url-pattern>/newdesign/manage/home/</url-pattern>
                <url-pattern>/newdesign/manage/home/*</url-pattern>

                <!-- Explicitly mention /welcome.do for usage as welcome page -->
                <url-pattern>/welcome/welcome.do</url-pattern>
        </servlet-mapping>
...

和这个控制器:

/** 
     * 
     */
    @RequestMapping(value = { "/newdesign/manage/home", 
                              "/newdesign/manage/home/",
                              "/newdesign/manage/manageapplications", 
                              "/newdesign/manage/manageapplications/"}, method = {RequestMethod.GET})
    public String manageApplications    (@ModelAttribute("aplicationListForm") final AplicationListForm aplicationListForm,
                                         HttpServletRequest request,
                                         Model model ) throws ExecutionException {


        User sessionUser = (User)request.getSession().getAttribute(Const.SESSION_USER);
        ..
}

此网址正常

/newdesign/manage/manageapplications

但是这一个newdesign/manage/home

我收到了这个错误

WARNING: No mapping found for HTTP request with URI [/devices/newdesign/manage/home]

我真的疯了!

我也尝试将它放在另一个具有相同结果的方法中

@RequestMapping(value = { "/newdesign/manage/home", 
                              "/newdesign/manage/home/"}, method = {RequestMethod.GET})
    public String cbHome    (Model model ) throws ExecutionException {
    ..
}

此网址正常运行 http://127.0.0.1:7001/devices/newdesign/manage/manageapplications 不是这个(?!) http://127.0.0.1:7001/devices/newdesign/manage/home

1 个答案:

答案 0 :(得分:0)

您的配置无效,因为在您的web.xml中,您的应用程序仅限于使用这些网址:

<url-pattern>/newdesign/manage/manageapplications</url-pattern>    
<url-pattern>/newdesign/manage/manageapplications/</url-pattern>
<url-pattern>/newdesign/manage/manageapplications/*</url-pattern>

这是一个典型的web.xml:

<servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
</servlet>


<servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

使用此配置,您告诉Spring使用dispatcher servlet机制来处理传入请求和视图呈现。通过这种方式,他可以处理您在控制器中定义的所有URL,例如/newdesign/manage/home

您需要创建用于配置调度程序的dispatcher-servlet.xml文件。

有关详细信息,请参阅此链接:http://www.mkyong.com/spring-mvc/spring-mvc-hello-world-example/