【问题标题】:Spring 3 No mapping found for HTTP request BeginnerSpring 3 No mapping found for HTTP request 初学者
【发布时间】:2012-01-24 17:03:11
【问题描述】:

我只是在尝试给出上述错误消息的示例

2011 年 12 月 21 日上午 12:14:46 org.springframework.web.servlet.DispatcherServlet noHandlerFound 警告:在名称为“mvc-dispatcher”的 DispatcherServlet 中未找到带有 URI [/BOL/home] 的 HTTP 请求的映射

下面是代码

package in.kukku.bol.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping("/home")
public class Home {

@RequestMapping(method = RequestMethod.GET)
public String printMsg(ModelMap model) {
    model.addAttribute("msg", "hi");
    return "index";
    }
}

mvc-dispatcher servlet

<context:component-scan base-package="in.kukku.bol.controller" />

<bean
    class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix">
        <value>/</value>
    </property>
    <property name="suffix">
        <value>.jsp</value>
    </property>
</bean>

web.xml

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

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

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/mvc-dispatcher-servlet.xml</param-value>
</context-param>

<listener>
    <listener-class>
        org.springframework.web.context.ContextLoaderListener
    </listener-class>
</listener>

你能告诉我哪里错了

【问题讨论】:

    标签: java spring jakarta-ee spring-mvc


    【解决方案1】:

    我在方法中添加了请求映射 url 格式。然后我修改了 web.xml 文件,它开始工作了。

    【讨论】:

    【解决方案2】:

    您似乎正在尝试通过/BOL URL 访问应用程序,因为您尚未定义控制器,请尝试使用{APP_CONTEXT}/home 访问它

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-12-06
      • 1970-01-01
      • 2017-05-14
      • 2015-04-06
      • 2016-12-13
      • 2023-03-29
      • 2015-03-23
      相关资源
      最近更新 更多