springmvc
来源:互联网 发布:usb虚拟打印机端口设置 编辑:程序博客网 时间:2024/05/22 14:46
原文地址:http://www.cnblogs.com/notDog/p/4735334.html
创建了一个空的SpringMVC项目,Tomcat可以正常启动,但是运行的时候,始终进不了Controller,并且报404错误。
百度各种查,结果也是查不到原因。各个群里面各种求,各种贴源码,也没有大神给解决。花了整整一天也没有搞出来,就在快要崩溃的时候,必应了一下子,
终于功夫不负有心人,在一篇文章的评论中找到了答案。
大家如有有闲工夫,可以来找找茬。
源码如下:
web.xml
<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"> <servlet> <servlet-name>springmvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/springmvc-servlet.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>springmvc</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.jsp</welcome-file> </welcome-file-list></web-app>
springmvc-servlet.xml
<?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.0.xsd"> <!--默认注解映射的支持 --> <mvc:annotation-driven /> <!--自动扫描目录下所有的类文件 --> <context:component-scan base-package="com.myspringmvc.controller.*" /> <!--对模型视图名称的解析 --> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/jsp/" /> <property name="suffix" value=".jsp" /> </bean></beans>
TestController.java
package com.myspringmvc.controller;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;@Controllerpublic class TestController { @RequestMapping(value="/test",method={RequestMethod.GET,RequestMethod.POST}) public String test() { return "test"; }}
访问页面:
如果今后有人在出现这种错误,希望可以帮助他。
O(∩_∩)O~ 你发现问题所在了吗?
解决方案如下:
<!--自动扫描目录下所有的类文件 --> <context:component-scan base-package="com.myspringmvc.controller.*" />----改为---->>>> <!--自动扫描目录下所有的类文件 --> <context:component-scan base-package="com.myspringmvc.controller" />
真坑爹啊.......
0 0
- SpringMVC
- springmvc
- SpringMVC
- SpringMVC
- springMvc
- springMVC
- springmvc
- springMVC
- springMVC
- springmvc
- SpringMVC
- SpringMVC
- springMvc
- springmvc
- springmvc
- SpringMVC
- Springmvc
- springmvc
- 把握嵌入式系统演变的每次脉动-工控资料窝
- 同一个wifi 有些手机不能链接 是怎么回事?
- C++虚函数表解析
- Shell学习之路-(01-Shell使用介绍)
- shell中的${},##和%%的使用
- springmvc
- 无穷分数
- web前端遇到的部分兼容问题汇总
- PTA刷题--查验身份证
- Roman to Integer
- pullToRefreshListView去掉顶部和底部分割线方法
- Mac office 字体和字号显示问题
- 属性取值、赋值点与中括号操作符的区别
- NSJSONSerliazition文档翻译和使用