spring MVC 配置错误
2016-04-08 15:44
441 查看
最近学习spring MVC, 发现不懂原理直接按照网上的小例子配置, 遇到错误真的崩溃
环境: spring3..1.1
src 目录
com.mvc.rest
RestController.java
错误:
http://localhost:8080/springMVC/welcome
显示:
type Status report
message
description The requested resource is not available.
日志:
2016-04-08 15:40:22 Did not find handler method for [/welcome]
2016-04-08 15:40:22 No mapping found for HTTP request with URI [/springMVC/welcome] in DispatcherServlet with name 'spring'
2016-04-08 15:40:22 Successfully completed request
解决方法:
将spring-servlet.xml中配置
<mvc:annotation-driven/>
<context:component-scan base-package="com.mvc.rest/*"></context:component-scan>
改为
<mvc:annotation-driven/>
<context:component-scan base-package="com.mvc.rest"></context:component-scan>
或者
<mvc:annotation-driven/>
<context:component-scan base-package="com.mvc.**"></context:component-scan>
因为 base-package 扫描的是包路径, 如果配置com.mvc.rest.* 扫描的是com.mvc.rest下的子包路,因为com.mvc.rest下没有子包路径
如果配置的com.mvc.* 则扫描com.mvc下所有的子包路径,因为RestController 在rest子包下,所以可以查找到
环境: spring3..1.1
src 目录
com.mvc.rest
RestController.java
错误:
http://localhost:8080/springMVC/welcome
显示:
HTTP Status 404 -
type Status reportmessage
description The requested resource is not available.
Apache Tomcat/8.0.9
日志:2016-04-08 15:40:22 Did not find handler method for [/welcome]
2016-04-08 15:40:22 No mapping found for HTTP request with URI [/springMVC/welcome] in DispatcherServlet with name 'spring'
2016-04-08 15:40:22 Successfully completed request
解决方法:
将spring-servlet.xml中配置
<mvc:annotation-driven/>
<context:component-scan base-package="com.mvc.rest/*"></context:component-scan>
改为
<mvc:annotation-driven/>
<context:component-scan base-package="com.mvc.rest"></context:component-scan>
或者
<mvc:annotation-driven/>
<context:component-scan base-package="com.mvc.**"></context:component-scan>
因为 base-package 扫描的是包路径, 如果配置com.mvc.rest.* 扫描的是com.mvc.rest下的子包路,因为com.mvc.rest下没有子包路径
如果配置的com.mvc.* 则扫描com.mvc下所有的子包路径,因为RestController 在rest子包下,所以可以查找到
相关文章推荐
- 一个jar包里的网站
- 一个jar包里的网站之文件上传
- 一个jar包里的网站之返回对媒体类型
- Spring Boot 开发微服务
- Spring整合Quartz(JobDetailBean方式)
- Spring整合Quartz(JobDetailBean方式)
- 模拟Spring的简单实现
- Spring整合WebSocket应用示例(上)
- spring+html5实现安全传输随机数字密码键盘
- Spring中属性注入详解
- springmvc 发送ajax出现中文乱码的解决方法汇总
- SpringMVC框架下JQuery传递并解析Json格式的数据是如何实现的
- struts2 spring整合fieldError问题
- spring的jdbctemplate的crud的基类dao
- 读取spring配置文件的方法(spring读取资源文件)
- Spring Bean基本管理实例详解
- java实现简单美女拼图游戏
- 详解Java的Spring框架中的事务管理方式
- 解析Java的Spring框架的BeanPostProcessor发布处理器
- Java开发框架spring实现自定义缓存标签