spring mvc 常见错误
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 常见错误的更多相关文章
- eclipse-java/spring mvc常见错误
Dynamic Web Module 3.1 requires Java 1.7 or newer http://crunchify.com/how-to-solve-dynamic-web-modu ...
- MVC MVC常见错误及解决办法
MVC常见错误及解决办法 问题1: 必须添加对程序集“EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c5 ...
- spring mvc:exclude-mapping错误提示
今天搭建一个java web项目时,增加了一个登录的拦截器,主要功能就是未登录的用户无法访问系统的任何页面. 先说明下我的web项目springmvc的版本以及刚开始配置的拦截器: springmvc ...
- spring + myBatis 常见错误:注解事务不回滚
最近项目在用springMVC+spring+myBatis框架,在配置事务的时候发现一个事务不能回滚的问题. 刚开始配置如下:springMVC.xml配置内容: spring.xml配置内容 从上 ...
- spring + myBatis 常见错误:SQL语法错误
在程序运行时,有时候会出现如下错误: 这个错误通常是你的sqlmapper.xml中sql语句语法有错误.所以请仔细查看你sql语句是否正确,比如{#id}这样写就会报上述错误,其实应该#{id}这样 ...
- spring + myBatis 常见错误:@Autowired注解失败
今天配置spring+myBatis的时候,使用注解@Autowired把持久层dao注入service层的时候总是报错. 查了好久才发现,居然是配置文件路径写错了.basepackge的路径一定要正 ...
- spring mvc 初始化错误
java.lang.NoSuchMethodError: org.springframework.util.ClassUtils.isPresent(Ljava/lang/String;Ljava/l ...
- Spring MVC常见的三种URL请求参数的处理
//方法1:@RequestParam //url:/test1?id=123 @RequestMapping(value = "/test1",method = RequestM ...
- spring mvc 500错误Allocate exception for servlet AppService javax.naming.NamingException: Cannot create resource instance 竟是@Resource的原因
头几天已经测试的完毕了,换了个目录出现这个问题 严重: Allocate exception for servlet AppService javax.naming.NamingException: ...
随机推荐
- windows server core 远程桌面
要允许其它计算机透过远程桌面登入Server Core主机,我们需要先调整注册机码,并开启对应的防火墙端口号首先,我们开启登录编辑程序(regedit.exe),找到HKEY_LOCAL_MACHIN ...
- MySQL 单条记录长度最大65535
今天设计表结构,加了几个字段,结果报错了 Ligne trop grande. Le taille maximale d'une ligne, sauf les BLOBs, est 65535... ...
- ThinkPHP 3.1.2 CURD特性 -3
一.ThinkPHP 3 的CURD介绍 (了解) 二.ThinkPHP 3 读取数据 (重点) 对数据的读取 Read $m=new Model('User'); $m=M('User'); ...
- Spring-framework应用程序启动loadtime源码分析笔记(一)
1,实例化DefaultListableBeanFactory DefaultListableBeanFactory是AnnotationConfigApplicationContext的组件,Def ...
- 透过CAT,来看分布式实时监控系统的设计与实现
2011年底,我加入大众点评网,出于很偶然的机会,决定开发CAT,为各个业务线打造分布式实时监控系统,CAT的核心概念源自eBay闭源系统CAL----eBay的几大法宝之一. 在当今互联网时代,业务 ...
- Java NIO系列教程(三) Channel之Socket通道
目录: <Java NIO系列教程(二) Channel> <Java NIO系列教程(三) Channel之Socket通道> 在<Java NIO系列教程(二) Ch ...
- 学习笔记之Everything
Everything (software) - Wikipedia https://en.wikipedia.org/wiki/Everything_(software) Everything is ...
- HDOJ 2005 第几天?
#include<iostream> using namespace std; ] = { ,,,,,,,,,,, }; ] = { ,,,,,,,,,,, }; bool isRYear ...
- 一次聊天引发的思考--java并发包
一次聊天,谈到了死锁的解决.可重入锁等等,突然发现这些离自己很远,只有一些读书时的概念涌入脑海,但各自的应用场景怎么都无法想出.痛定思痛,决定看看concurrent包里涉及并发的类及各自的应用场景. ...
- confluence部署与破解
一.confluence安装 #安装环境环境 centos7.jdk8.mysql5.7.Confluence6.14.1 confluence下载地址 wget https://product-do ...