Spring MVC-找不到带有URI的HTTP请求的映射 [英] Spring MVC - No mapping found for HTTP request with URI

查看:488
本文介绍了Spring MVC-找不到带有URI的HTTP请求的映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道关于该主题有很多问题,但是我在这里找到的所有解决方案都没有为我工作. 我将Spring与Jetty 6结合使用,所以没有web.xml文件.在jetty的配置中,将Spring调度程序servlet的映射设置为"/"

I'm aware that there are loads of questions on the topic but none of the solutions i found here worked for me. I'm using Spring with Jetty 6 so i don't have a web.xml file. The mapping for the spring dispatcher servlet is set to "/" in jetty's config

调度程序:

<bean class="org.mortbay.jetty.servlet.ServletHolder">
    <property name="name" value="spring" />
    <property name="servlet">
        <bean class="org.springframework.web.servlet.DispatcherServlet" />
    </property>
    <property name="initParameters">
        <map>
            <entry key="contextConfigLocation" value="classpath:com/project/config/spring-servlet.xml" />
        </map>
    </property>
</bean>

...映射:

<bean class="org.mortbay.jetty.servlet.ServletMapping">
    <property name="servletName" value="spring"></property>
    <property name="pathSpec" value="/"></property>
</bean>

spring-servlet.xml看起来像这样:

The spring-servlet.xml looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="..." ...>


<context:component-scan base-package="com.project.web" />
<mvc:annotation-driven />

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

</beans>

我有一个名为HelloController的简单控制器:

And i have a simple controller called HelloController:

@Controller
public class HelloController {

    @RequestMapping(method = RequestMethod.GET, value="/welcome")
    public String sayHello(ModelMap model){
    model.addAttribute("message", "Spring 3 MVC Hello World");
    return "hello";
}

}

阅读日志似乎正常,但是出现以下错误:

Reading the logs it seem to work but i get the following error:

在DispatcherServlet中找不到名称为'spring'的URI [/WEB-INF/pages/hello.jsp]的HTTP请求的映射

No mapping found for HTTP request with URI [/WEB-INF/pages/hello.jsp] in DispatcherServlet with name 'spring'

我不明白.它将"/welcome"映射到/WEB-INF/pages/hello.jsp,但它仍然说找不到页面,而页面似乎就在那儿.我将WEB-INF文件夹添加到类路径中,但仍然相同.你知道为什么吗?

which i don't understand. it maps the "/welcome" to /WEB-INF/pages/hello.jsp but it still says page cannot be found, which is just there where it seems to look for it. I added the WEB-INF folder to the classpath but it's still the same. Do you have any idea why's that?

推荐答案

您确定软件包名称正确吗?

Are you sure the package name is correct in this?

<context:component-scan base-package="com.project.web" />

这篇关于Spring MVC-找不到带有URI的HTTP请求的映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆