运行环境:jdk1.7.0_17 + tomcat 7 + spring 3.2.0 +mybatis 3.2.7+ eclipse,访问路径:http://localhost:8085/Springmvc_Mybits_store/queryItems.do

  错误: 导致404 错误,一般是转发路径写错误,还有是请求时候书写错误找不到Handler仔细检查路径是否写对,今天要讲的错误,也可以说是比较粗心的犯的错,但对于新手没法找出来,在路径对的情况下,我们访问404错误,并且地址打印出来也是对的。

  错误原因 :查看controller导入的包:原因就在這两个包,由于现在还不能充分解释,当时写的时候是自动注入的包,注入是import org.springframework.web.portlet.ModelAndView;这是错误根本原因,找了资料大体解释下这两个的区别,在这两个包里面的

  ModelAndView 里面内容都是一样的,这两个是为适用不同的环境。

    org.springframework.web.portlet.ModelAndView:是一个支持处理方法的返回类型:意味着spring有一个HandlerMethodReturnValueHandler实现(ModelAndViewMethodReturnValueHandler),它将接收类型的返回值ModelAndView并处理它

    org.springframework.web.servlet.ModelAndView:默认情况下没有注册的实现。

  解决办法:删除原有的org.springframework.web.portlet.ModelAndView 导入org.springframework.web.servlet.ModelAndView

  错误代码:控制台无报错,页面404错误;

      

 发送请求的日志文件:

 DispatcherServlet with name 'springmvc' processing GET request for [/Springmvc_Mybits_store/queryItems.do]
Looking up handler method for path /queryItems.do
Returning handler method [public org.springframework.web.portlet.ModelAndView com.kjczwl.ssm.controller.ItemsController.queryItems() throws java.lang.Exception]
Returning cached instance of singleton bean 'itemsController'
Last-Modified value for [/Springmvc_Mybits_store/queryItems.do] is: -1
Creating a new SqlSession
Registering transaction synchronization for SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@7adc9dc9]
Fetching JDBC Connection from DataSource
Registering transaction synchronization for JDBC Connection
JDBC Connection [jdbc:mysql://localhost:3306/store, UserName=root@localhost, MySQL Connector Java] will be managed by Spring
==> Preparing: SELECT * from items
==> Parameters:
<== Total: 4
Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@7adc9dc9]
Transaction synchronization deregistering SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@7adc9dc9]
Transaction synchronization closing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@7adc9dc9]
Returning JDBC Connection to DataSource
44444444444444444444444444444
Rendering view [org.springframework.web.servlet.view.JstlView: name 'queryItems'; URL [/WEB-INF/pages/items/queryItems.jsp]] in DispatcherServlet with name 'springmvc'
Added model object 'modelAndView' of type [org.springframework.web.portlet.ModelAndView] to request in view with name 'queryItems'
Added model object 'org.springframework.validation.BindingResult.modelAndView' of type [org.springframework.validation.BeanPropertyBindingResult] to request in view with name 'queryItems'
Forwarding to resource [/WEB-INF/pages/items/queryItems.jsp] in InternalResourceView 'queryItems'
Successfully completed request

  相关代码:

     工程结构:

      

 controller 代码:

  1 package com.kjczwl.ssm.controller;
2
3 import java.util.List;
4
5 import org.springframework.beans.factory.annotation.Autowired;
6 import org.springframework.stereotype.Controller;
7 import org.springframework.web.bind.annotation.RequestMapping;
8 import org.springframework.web.portlet.ModelAndView;
9 import com.kjczwl.ssm.po.ItemsCustom;
10 import com.kjczwl.ssm.service.ItemsService;
11
12 /**
13 *<p>package: com.kjczwl.ssm.controller</p>
14 *<p>Description:商品的controller(Handler) </p>
15 *<p>Company: Springmvc_Mybits_store</p>
16 *@author: 唐烈
17 * @date 2017下午5:30:58
18 */
19 @Controller// 注解模式开发Controller
20 public class ItemsController {
21 // 注入 从service 中取得数据
22 @Autowired
23 ItemsService itemsService;
24
25 //注解扫描, 后面映射地址 可通过queryItems.action 访问
26 @RequestMapping("/queryItems.do")
27 public ModelAndView queryItems()throws Exception{
28 //得到数据
29 List<ItemsCustom> itemList = itemsService.findItemsList(null);
30 // 构造ModelAndView
31 ModelAndView modelAndView = new ModelAndView("itemsList");
32 // 添加到内存区 外面直接“${} 条件表达式获取”
33 modelAndView.addObject("itemList",itemList);
34 //转发的路径 modelAndView.setViewName("itemsList");
35 return modelAndView;
36 }
37 }

springmvc 配置:

 <?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"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd">
<!-- =================================================================================== -->
<!-- 自动扫描注解 -->
<context:component-scan base-package="com.kjczwl.ssm.controller">
<!--
只扫描你规定的:<context:include-filter type="annotation" expression=""/>
不扫描你规定的:<context:exclude-filter type="annotation" expression=""/>
-->
</context:component-scan>
<!-- =================================================================================== -->
<!-- 注解驱动
代替:
处理器适配器
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"/>
处理器映射器
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"/>
-->
<mvc:annotation-driven/>
<!-- =================================================================================== -->
<!-- 视图解析器
前缀:prefix
后缀:suffix
-->
<mvc:default-servlet-handler/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/pages/items/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>

spring整合mybatis错误:HTTP Status 404 - xxx-xxx....的更多相关文章

  1. spring整合mybatis错误:class path resource [config/spring/springmvc.xml] cannot be opened because it does not exist

    spring 整合Mybatis 运行环境:jdk1.7.0_17+tomcat 7 + spring:3.2.0 +mybatis:3.2.7+ eclipse 错误:class path reso ...

  2. spring 整合Mybatis 错误:Parameter 'items_id' not found. Available parameters are [array]

    运行环境:jdk1.7.0_17+tomcat 7 + spring:3.2.0 +mybatis:3.2.7+ eclipse 错误:Parameter 'items_id' not found. ...

  3. spring整合mybatis错误:Could not autowire field: com.kjczwl.ssm.service.ItemsService com.kjczwl.ssm.controller.ItemsController.itemsservice;

    运行环境:jdk1.7.0_17+tomcat 7 + spring:3.2.0 +mybatis:3.2.7+ eclipse 错误:Could not autowire field: com.kj ...

  4. spring整合mybatis错误:Caused by: org.xml.sax.SAXParseException; lineNumber: 5; columnNumber: 62; 文档根元素 "mapper" 必须匹配 DOCTYPE 根 "configuration"。

    运行环境:jdk1.7.0_17+tomcat 7 + spring:3.2.0 +mybatis:3.2.7+ eclipse 错误:Caused by: org.xml.sax.SAXParseE ...

  5. Spring整合Mybatis错误解决方案

    ERROR:java.lang.AbstractMethodError: org.mybatis.spring.transaction.SpringManagedTransactionFactory. ...

  6. Spring整合MyBatis(二)Spring整合MyBatis

    摘要: 本文结合<Spring源码深度解析>来分析Spring 5.0.6版本的源代码.若有描述错误之处,欢迎指正. 了解了MyBatis的独立使用过程后,我们再看看它与Spring整合的 ...

  7. Spring整合MyBatis(一)MyBatis独立使用

    摘要: 本文结合<Spring源码深度解析>来分析Spring 5.0.6版本的源代码.若有描述错误之处,欢迎指正. MyBatis本是Apache的一个开源项目iBatis,2010年这 ...

  8. Spring学习总结(五)——Spring整合MyBatis(Maven+MySQL)二

    接着上一篇博客<Spring整合MyBatis(Maven+MySQL)一>继续. Spring的开放性和扩张性在J2EE应用领域得到了充分的证明,与其他优秀框架无缝的集成是Spring最 ...

  9. spring 整合Mybatis 《报错集合,总结更新》

    错误:java.lang.NoClassDefFoundError: org/aspectj/weaver/reflect/ReflectionWorld$ReflectionWorldExcepti ...

随机推荐

  1. Java 9 揭秘(20. JDK 9中API层次的改变)

    Tips 做一个终身学习的人. 在最后一章内容中,主要介绍以下内容: 下划线作为新关键字 改进使用try-with-resources块的语法 如何在匿名类中使用<>操作符 如何在接口中使 ...

  2. 如何让Oracle释放undo表空间

    如何让Oracle释放undo表空间   最佳答案   在日常的数据库维护和数据库编程中经常会遇到犹豫对大数据量做DML操作后是得ORACLE的undo表空间扩展到十几个G或者几十个G 但是这些表空间 ...

  3. [补档][HZOI 2016]简单的Treap

    [HZOI 2016]简单的Treap 题目 Treap是一种平衡二叉搜索树,除二叉搜索树的基本性质外,Treap还满足一个性质: 每个节点都有一个确定的优先级,且每个节点的优先级都比它的两个儿子小( ...

  4. APMServ中的 Apache无法启动…

    情况1. 找问题:C:\APMServ5.2.6\Apache\bin点击httpd.exe 会出现: path is invalid.(地址无效) 解决办法:找到C:/APMServ5.2.6/Ap ...

  5. 阿里云ECS主机自定义进程监控

    由于业务的关系我们用的是阿里云的ECS主机,需要对业务进程需要监控,查看后发现阿里云提供自定义监控SDK,这有助于我们定制化的根据自身业务来做监控,下面我就根据业务需求来介绍一个简单的自定义监控配置 ...

  6. Spring+SpringMVC+MyBatis+easyUI整合进阶篇(二)RESTful API实战笔记(接口设计及Java后端实现)

    写在前面的话 原计划这部分代码的更新也是上传到ssm-demo仓库中,因为如下原因并没有这么做: 有些使用了该项目的朋友建议重新创建一个仓库,因为原来仓库中的项目太多,结构多少有些乱糟糟的. 而且这次 ...

  7. NYOJ 69 数的长度(数学)

    数的长度 时间限制:3000 ms  |  内存限制:65535 KB 难度:1   描述 N!阶乘是一个非常大的数,大家都知道计算公式是N!=N*(N-1)······*2*1.现在你的任务是计算出 ...

  8. css的一些问题

    background-size ie8不支持怎么解决? background-size这个属性是css3,新增的属性,现在很多浏览器已经支持了,但是IE系列的浏览器却没有支持,比如IE8,下面介绍下如 ...

  9. Struts2.5的的环境搭建及跑通流程

    Struts2.5 struts是开源框架.使用Struts的目的是为了帮助我们减少在运用MVC设计模型来开发Web应用的时间.如果我们想混合使用Servlets和JSP的优点来建立可扩展的应用,st ...

  10. Spring集成RabbiMQ-Spring AMQP新特性

    上一篇<Spring集成RabbitMQ-使用RabbitMQ更方便>中,我们只需要添加响应jar的依赖,就可以写一个Spring集成RabbitMQ下非常简单收发消息的程序. 我们使用的 ...