SpringMVC配置问题

zplswf 发布于 2012/07/21 11:38
阅读 45K+
收藏 3

首先是web.xml

<servlet>

<servlet-name>spring</servlet-name>

<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

<load-on-startup>1</load-on-startup>

</servlet>

 

<servlet-mapping>

<servlet-name>spring</servlet-name>

<url-pattern>/</url-pattern>

</servlet-mapping>

然后是

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

<beans xmlns="http://www.springframework.org/schema/beans" 

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xmlns:p="http://www.springframework.org/schema/p" 

    xmlns:context="http://www.springframework.org/schema/context"

    xmlns:mvc="http://www.springframework.org/schema/mvc"

    xsi:schemaLocation="

        http://www.springframework.org/schema/beans 

        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

        http://www.springframework.org/schema/context 

        http://www.springframework.org/schema/context/spring-context-3.0.xsd

        http://www.springframework.org/schema/mvc 

        http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd

        ">

        <mvc:annotation-driven/>

       <context:component-scan base-package="com.zpl.controller.*"></context:component-scan>

       

        <bean id="viewResolver"

          class="org.springframework.web.servlet.view.InternalResourceViewResolver">

        <property name="prefix" value="/WEB-INF/jsp/"/>

        <property name="suffix" value=".jsp"/>

       </bean>

</beans>

最后是

package com.zpl.controller;

 

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.RequestMapping;

 

@Controller

public class HellowController {

 

@RequestMapping(value="/hello")

public String hello(){

System.out.println("hello");

return "hello";

}

}

运行的http://localhost:8080/项目/hello

No mapping found for HTTP request with URI [/spring_mvc/hello] in DispatcherServlet with name 'spring'


以下是问题补充:

@zplswf:2012-7-21 11:59:26 org.apache.catalina.core.ApplicationContext log 信息: SessionListener: contextInitialized() 2012-7-21 11:59:26 org.apache.catalina.startup.HostConfig deployDirectory 信息: Deploying web application directory spring_mvc 2012-7-21 11:59:33 org.apache.catalina.core.ApplicationContext log 信息: Initializing Spring FrameworkServlet 'spring' 2012-7-21 11:59:33 org.springframework.web.servlet.FrameworkServlet initServletBean 信息: FrameworkServlet 'spring': initialization started 2012-7-21 11:59:34 org.springframework.context.support.AbstractApplicationContext prepareRefresh 信息: Refreshing WebApplicationContext for namespace 'spring-servlet': startup date [Sat Jul 21 11:59:34 CST 2012]; root of context hierarchy 2012-7-21 11:59:35 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions 信息: Loading XML bean definitions from ServletContext resource [/WEB-INF/spring-servlet.xml] 2012-7-21 11:59:44 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons 信息: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@161ce13: defining beans [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#0,org.springframework.format.support.FormattingConversionServiceFactoryBean#0,org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter#0,org.springframework.web.servlet.handler.MappedInterceptor#0,org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver#0,org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver#0,org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver#0,org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping,org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter,org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,viewResolver,org.springframework.context.annotation.ConfigurationClassPostProcessor$ImportAwareBeanPostProcessor#0]; root of factory hierarchy 2012-7-21 11:59:47 org.springframework.web.servlet.FrameworkServlet initServletBean 信息: FrameworkServlet 'spring': initialization completed in 14000 ms 2012-7-21 11:59:47 org.apache.coyote.http11.Http11Protocol start 信息: Starting Coyote HTTP/1.1 on http-8080 2012-7-21 11:59:47 org.apache.jk.common.ChannelSocket init 信息: JK: ajp13 listening on /0.0.0.0:8009 2012-7-21 11:59:47 org.apache.jk.server.JkMain start 信息: Jk running ID=0 time=0/120 config=null 2012-7-21 11:59:47 org.apache.catalina.startup.Catalina start 信息: Server startup in 25595 ms 2012-7-21 11:59:53 org.springframework.web.servlet.DispatcherServlet noHandlerFound 警告: No mapping found for HTTP request with URI [/spring_mvc/hello] in DispatcherServlet with name 'spring' (2012/07/21 12:05)
加载中
0
zplswf
zplswf
日!解决了
zplswf
zplswf
回复 @demon_devil_jet : <context:component-scan base-package="com.zpl.controller.*"></context:component-scan>这个写错了。没有扫描到
demon_devil_jet
demon_devil_jet
什么包没有扫描到,然后怎么解决的?
zplswf
zplswf
我的原因是包没有扫描到
无知的小孩
无知的小孩
能问下怎么解决的吗
0
zplswf
zplswf
怎么没人会啊!帮帮忙吧
0
二零一九是猪年
二零一九是猪年

<servlet-mapping>

<servlet-name>spring</servlet-name>

<url-pattern>/*</url-pattern>

</servlet-mapping>

zplswf
zplswf
不行哈!我启动tomcat的时候在后台看日志都没有Handler上,不知到是什么情况
zplswf
zplswf
我试试哈
0
zplswf
zplswf
后台打印日志没有注册上 很郁闷
0
天朝惘民
在spring的配置文件 spring-servlet.xml 中添加如下一行:

<mvc:default-servlet-handler/>

或者修改@RequestMapping(value="/hello")为@RequestMapping(value="/hello.do")

zplswf
zplswf
<mvc:default-servlet-handler/>加上这句话Mapped URL path [/**] onto handler 'org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler#0'把所有的都注册上!还是不行
0
二零一九是猪年
二零一九是猪年

还是看官方的文档自己先调试出来!然后再调试自己的东西!

http://static.springsource.org/spring/docs/3.0.x/reference/mvc.html

zplswf
zplswf
我就是参考官网的的
0
JFinal
JFinal
A clever person solves a problem. A wise person avoids it.  @JFinal 避免 xml
JFinal
JFinal
回复 @张培立 : 谢谢 :)
zplswf
zplswf
回复 @JFinal : 好的!遇到什么问题!我会及时反馈
JFinal
JFinal
回复 @张培立 : 理解,但可以凭自己的努力慢慢改变现状的。@JFinal 使用者越来越多了,欢迎多来提建议 :)
zplswf
zplswf
回复 @JFinal : 自己看过点,研究过点,却是不错!可我不是项目经理呵呵 !
JFinal
JFinal
回复 @张培立 : 为何不试试 @JFinal 呢,SSH浪费了多少青春啊
下一页
0
小白小霸王
小白小霸王
在@Control下面写上 
@RequestMapping(" spring_mvc")
zplswf
zplswf
why
0
小白小霸王
小白小霸王
http://127.0.0.1:8080/project/ctrl/method.do

@Controller
@RequestMapping("ctrl")
public class ctrl
{
    @RequestMapping("method")
    public ModelAndView method()
    {
        return null;
    } 
}
zplswf
zplswf
回复 @光头程序员 : 谢了我看看
小白小霸王
小白小霸王
回复 @张培立 : springmvc Demo svn地址 http://code.taobao.org/svn/springmvcdemo/trunk 仅供参考
zplswf
zplswf
no
0
piaohao
piaohao
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />

用上面这个替换掉下面这个

<mvc:annotation-driven/>

zplswf
zplswf
No mapping found for HTTP request with URI [/spring_mvc/hello] in DispatcherServlet with name 'spring' 还是报这个问题
返回顶部
顶部