1 返回400,

   —— 请求参数不正确

2 返回406,

HTTP ERROR: 406

NOT_ACCEPTABLE
 ————
@RequestMapping(value = "/user/byAcc",
method = RequestMethod.GET,
produces = MediaType.APPLICATION_XML_VALUE + ";charset=UTF-8")

   —— 请求结果无法正确渲染,请求返回的是xml 就导致springmvc 无法解析了。。。 那就加上jackson-xml:

<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>${jackson.version}</version>
</dependency>

3 直接返回viewName,而不是viewName对应的 view(如jsp,velocity)

  这个通常是因为方法前有@ResponseBody注解导致的,或者方法对应类前有 @RestController,

4  jetty 启动的时候出错:

java.lang.NoSuchMethodError: com.fasterxml.jackson.databind.SerializationConfig.withDefaultPrettyPrinter(Lcom/fasterxml/jackson/core/PrettyPrinter;)Lcom/fasterxml/jackson/databind/SerializationConfig;

 Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter]: Factory method 'mappingJackson2XmlHttpMessageConverter' threw exception; nested exception is java.lang.NoSuchMethodError: com.fasterxml.jackson.databind.SerializationConfig.withDefaultPrettyPrinter(Lcom/fasterxml/jackson/core/PrettyPrinter;)Lcom/fasterxml/jackson/databind/SerializationConfig;
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:)
... more
Caused by: java.lang.NoSuchMethodError: com.fasterxml.jackson.databind.SerializationConfig.withDefaultPrettyPrinter(Lcom/fasterxml/jackson/core/PrettyPrinter;)Lcom/fasterxml/jackson/databind/SerializationConfig;
at com.fasterxml.jackson.dataformat.xml.XmlMapper.<init>(XmlMapper.java:)
at com.fasterxml.jackson.dataformat.xml.XmlMapper.<init>(XmlMapper.java:)
at com.fasterxml.jackson.dataformat.xml.XmlMapper.<init>(XmlMapper.java:)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at org.springframework.beans.BeanUtils.instantiate(BeanUtils.java:)
at org.springframework.http.converter.json.Jackson2ObjectMapperBuilder.build(Jackson2ObjectMapperBuilder.java:)
at org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter.<init>(MappingJackson2XmlHttpMessageConverter.java:)
at org.springframework.boot.autoconfigure.web.JacksonHttpMessageConvertersConfiguration$MappingJackson2XmlHttpMessageConverterConfiguration.mappingJackson2XmlHttpMessageConverter(JacksonHttpMessageConvertersConfiguration.java:)
at org.springframework.boot.autoconfigure.web.JacksonHttpMessageConvertersConfiguration$MappingJackson2XmlHttpMessageConverterConfiguration$$EnhancerBySpringCGLIB$$f2b9ded.CGLIB$mappingJackson2XmlHttpMessageConverter$(<generated>)
at org.springframework.boot.autoconfigure.web.JacksonHttpMessageConvertersConfiguration$MappingJackson2XmlHttpMessageConverterConfiguration$$EnhancerBySpringCGLIB$$f2b9ded$$FastClassBySpringCGLIB$$911122bf.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:)
at org.springframework.boot.autoconfigure.web.JacksonHttpMessageConvertersConfiguration$MappingJackson2XmlHttpMessageConverterConfiguration$$EnhancerBySpringCGLIB$$f2b9ded.mappingJackson2XmlHttpMessageConverter(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:)
... more

原因是版本不匹配, spring MVC 4.3.6.RELEASE 和 com.fasterxml.jackson.core 的2.8.8 不兼容,或者jackson-annotations 和 jackson-core 的版本没有一致。 (2.8.8 是 我手动添加的com.fasterxml.jackson.core 的最新版本),把 com.fasterxml.jackson.core  版本改为 2.5.0 就ok了!!

5 ModelAndView 的view设置没有生效,

@RequestMapping(value="/index_html", method=RequestMethod.GET)
public ModelAndView indexView(){
System.out.println("++++++++++++++");
ModelAndView mv = new ModelAndView("index");
mv.setViewName("abc"); // 期望解析到abc.jsp , 结果是index_html.jsp ,然后就出现了 404 ..
    return mv;
}

应该是import org.springframework.web.servlet.ModelAndView;

我居然不小心引入了import org.springframework.web.portlet.ModelAndView;

参考http://bbs.csdn.net/topics/390543354

 

spring mvc 常见错误的更多相关文章

  1. eclipse-java/spring mvc常见错误

    Dynamic Web Module 3.1 requires Java 1.7 or newer http://crunchify.com/how-to-solve-dynamic-web-modu ...

  2. MVC MVC常见错误及解决办法

    MVC常见错误及解决办法 问题1: 必须添加对程序集“EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c5 ...

  3. spring mvc:exclude-mapping错误提示

    今天搭建一个java web项目时,增加了一个登录的拦截器,主要功能就是未登录的用户无法访问系统的任何页面. 先说明下我的web项目springmvc的版本以及刚开始配置的拦截器: springmvc ...

  4. spring + myBatis 常见错误:注解事务不回滚

    最近项目在用springMVC+spring+myBatis框架,在配置事务的时候发现一个事务不能回滚的问题. 刚开始配置如下:springMVC.xml配置内容: spring.xml配置内容 从上 ...

  5. spring + myBatis 常见错误:SQL语法错误

    在程序运行时,有时候会出现如下错误: 这个错误通常是你的sqlmapper.xml中sql语句语法有错误.所以请仔细查看你sql语句是否正确,比如{#id}这样写就会报上述错误,其实应该#{id}这样 ...

  6. spring + myBatis 常见错误:@Autowired注解失败

    今天配置spring+myBatis的时候,使用注解@Autowired把持久层dao注入service层的时候总是报错. 查了好久才发现,居然是配置文件路径写错了.basepackge的路径一定要正 ...

  7. spring mvc 初始化错误

    java.lang.NoSuchMethodError: org.springframework.util.ClassUtils.isPresent(Ljava/lang/String;Ljava/l ...

  8. Spring MVC常见的三种URL请求参数的处理

    //方法1:@RequestParam //url:/test1?id=123 @RequestMapping(value = "/test1",method = RequestM ...

  9. spring mvc 500错误Allocate exception for servlet AppService javax.naming.NamingException: Cannot create resource instance 竟是@Resource的原因

    头几天已经测试的完毕了,换了个目录出现这个问题 严重: Allocate exception for servlet AppService javax.naming.NamingException: ...

随机推荐

  1. 【微软版本】redis 安装启动及设置密码<windows>

    redis 安装启动及设置密码<windows>   redis 1. 安装 1.1 下载解压包,直接解压到任意路径下即可 windows下载地址:ttps://github.com/MS ...

  2. synchronized基础

    synchronized 例子 例1,没有同步的时候运行同一个对象的同一个方法的结果: public class TestSyn { public void showMsg() { try { for ...

  3. webstorm 破解码

    https://blog.csdn.net/voke_/article/details/76418116 摘自此博客

  4. IDC:IDC 清单

    ylbtech-IDC:IDC 清单 1.返回顶部   2.返回顶部   3.返回顶部   4.返回顶部   5.返回顶部     6.返回顶部   作者:ylbtech出处:http://ylbte ...

  5. base_基础

    目录 A B C D E F G H I J K L M N S: Sqlite: 1;orhanobut/hawk; A: Adapter: 图片处理 Android中自定义布局中加载图片Bitma ...

  6. 浅析Linux DeviceTree

    文本将介绍Linux DeviceTree的相关知识,包括DeviceTree源文件.结构.语法.编写规则等. DeviceTree基础 DeviceTree(以下简称DT)用于描述设备信息以及设备于 ...

  7. sas infile 控制导入长度

    /*尝试使用infile解决uesrname的录入只能存储一单位的问题*/data TestPayRecord2;infile "D:\开发工具\购买记录表.csv" dlm='2 ...

  8. Apache poi简介及代码操作Excel

    一.简介 在我们进行企业的系统开发时,难免会遇到网页表格和Excel之间的操作问题(POI是个不错的选择) Apache POI是Apache软件基金会的开放源码函式库,POI提供API给Java程序 ...

  9. Java - 22 Java 多态

    Java 多态 多态是同一个行为具有多个不同表现形式或形态的能力. 多态性是对象多种表现形式的体现. 比如我们说"宠物"这个对象,它就有很多不同的表达或实现,比如有小猫.小狗.蜥蜴 ...

  10. EventBus的使用;消息传递之EventBus;

    EventBus传递消息(数据)和广播有点像,对广播传递数据有兴趣的可以看一下:Android数据传递,使用广播BroadcastReceiver: 1.添加build.gradle implemen ...