简体   繁体   中英

Spring 3 No mapping found for HTTP request Beginner

I'm just trying out a sample that gave the above error message

21 Dec, 2011 12:14:46 AM org.springframework.web.servlet.DispatcherServlet noHandlerFound WARNING: No mapping found for HTTP request with URI [/BOL/home] in DispatcherServlet with name 'mvc-dispatcher'

Following is the code

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>

Can you tell me where I'm wrong

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

I added request mapping url format to methods. Then I altered web.xml file and it started working.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM