关闭

Spring集成JSON报错:java.lang.ClassNotFoundException: org.codehaus.jackson.JsonProcessingException

标签: springjson异常org.codehaus.jackson
8412人阅读 评论(4) 收藏 举报
分类:

先看异常信息:

SEVERE: StandardWrapper.Throwable
java.lang.NoClassDefFoundError: org/codehaus/jackson/JsonProcessingException
	at java.lang.Class.getDeclaredConstructors0(Native Method)
	at java.lang.Class.privateGetDeclaredConstructors(Class.java:2493)
	at java.lang.Class.getDeclaredConstructors(Class.java:1901)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:234)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineConstructorsFromBeanPostProcessors(AbstractAutowireCapableBeanFactory.java:1040)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1013)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:700)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
	at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:658)
	at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:624)
	at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:672)
	at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:543)
	at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:484)
	at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
	at javax.servlet.GenericServlet.init(GenericServlet.java:158)
	at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1231)
	at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1144)
	at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1031)
	at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4909)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5196)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:725)
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:701)
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:717)
	at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1069)
	at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1719)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
	at java.util.concurrent.FutureTask.run(FutureTask.java:262)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at java.lang.Thread.run(Thread.java:744)
Caused by: java.lang.ClassNotFoundException: org.codehaus.jackson.JsonProcessingException
	at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1305)
	at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1157)
	... 38 more

看我们的pom.xml配置:

<properties>
		<!-- spring版本号 -->
		<spring.version>4.0.2.RELEASE</spring.version>
		<!-- mybatis版本号 -->
		<mybatis.version>3.2.6</mybatis.version>
		<!-- log4j日志文件管理包版本 -->
		<slf4j.version>1.7.7</slf4j.version>
		<log4j.version>1.2.17</log4j.version>
		<jackson.version>2.8.1</jackson.version>
	</properties>

	<dependencies>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.11</version>
			<!-- 表示开发的时候引入,发布的时候不会加载此包 -->
			<scope>test</scope>
		</dependency>
		<!-- spring核心包 -->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-core</artifactId>
			<version>${spring.version}</version>
		</dependency>

		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-web</artifactId>
			<version>${spring.version}</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-oxm</artifactId>
			<version>${spring.version}</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-tx</artifactId>
			<version>${spring.version}</version>
		</dependency>

		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-jdbc</artifactId>
			<version>${spring.version}</version>
		</dependency>

		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-webmvc</artifactId>
			<version>${spring.version}</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-aop</artifactId>
			<version>${spring.version}</version>
		</dependency>

		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-context-support</artifactId>
			<version>${spring.version}</version>
		</dependency>

		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-test</artifactId>
			<version>${spring.version}</version>
		</dependency>
		<!-- mybatis核心包 -->
		<dependency>
			<groupId>org.mybatis</groupId>
			<artifactId>mybatis</artifactId>
			<version>${mybatis.version}</version>
		</dependency>
		<!-- mybatis/spring包 -->
		<dependency>
			<groupId>org.mybatis</groupId>
			<artifactId>mybatis-spring</artifactId>
			<version>1.2.2</version>
		</dependency>
		<!-- 导入java ee jar 包 -->
		<dependency>
			<groupId>javax</groupId>
			<artifactId>javaee-api</artifactId>
			<version>7.0</version>
		</dependency>
		<!-- 导入Mysql数据库链接jar包 -->
		<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
			<version>5.1.30</version>
		</dependency>
		<!-- 导入dbcp的jar包,用来在applicationContext.xml中配置数据库 -->
		<dependency>
			<groupId>commons-dbcp</groupId>
			<artifactId>commons-dbcp</artifactId>
			<version>1.2.2</version>
		</dependency>
		<!-- JSTL标签类 -->
		<dependency>
			<groupId>jstl</groupId>
			<artifactId>jstl</artifactId>
			<version>1.2</version>
		</dependency>
		<!-- 日志文件管理包 -->
		<!-- log start -->
		<dependency>
			<groupId>log4j</groupId>
			<artifactId>log4j</artifactId>
			<version>${log4j.version}</version>
		</dependency>


		<!-- 格式化对象,方便输出日志 -->
		<dependency>
			<groupId>com.alibaba</groupId>
			<artifactId>fastjson</artifactId>
			<version>1.1.41</version>
		</dependency>

		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-api</artifactId>
			<version>${slf4j.version}</version>
		</dependency>

		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-log4j12</artifactId>
			<version>${slf4j.version}</version>
		</dependency>
		<!-- log end -->
		<!-- 映入JSON -->
	<span style="color:#ff0000;">	<dependency>
			<groupId>com.fasterxml.jackson.core</groupId>
			<artifactId>jackson-databind</artifactId>
			<version>${jackson.version}</version>
		</dependency>
		<dependency>
			<groupId>com.fasterxml.jackson.core</groupId>
			<artifactId>jackson-annotations</artifactId>
			<version>${jackson.version}</version>
		</dependency>
		<dependency>
			<groupId>com.fasterxml.jackson.core</groupId>
			<artifactId>jackson-core</artifactId>
			<version>${jackson.version}</version>
		</dependency></span>
		<!-- 上传组件包 -->
		<dependency>
			<groupId>commons-fileupload</groupId>
			<artifactId>commons-fileupload</artifactId>
			<version>1.3.1</version>
		</dependency>
		<dependency>
			<groupId>commons-io</groupId>
			<artifactId>commons-io</artifactId>
			<version>2.4</version>
		</dependency>
		<dependency>
			<groupId>commons-codec</groupId>
			<artifactId>commons-codec</artifactId>
			<version>1.9</version>
		</dependency>
		<dependency>
			<groupId>org.apache.httpcomponents</groupId>
			<artifactId>httpclient</artifactId>
			<version>4.5.2</version>
		</dependency>

	</dependencies>

可以看到红色的jackson已经被配置进去了,为什么还报错?

经过排查发现Spring的配置是从网上拷贝的,版本比较老,其中关于json的配置是:

 <!--避免IE执行AJAX时,返回JSON出现下载文件 -->  
    <bean id="mappingJacksonHttpMessageConverter"  
        class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">  
        <property name="supportedMediaTypes">  
            <list>  
                <value>text/html;charset=UTF-8</value>  
            </list>  
        </property>  
    </bean>  
如果将Spring的版本提高到最新的版本(4.3.2.RELEASE),这里其实是会报错的。

原来是实现类变化了,现在更改为:

        class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">  
        <property name="supportedMediaTypes">  
            <list>  
                <value>text/html;charset=UTF-8</value>  
            </list>  
        </property>  
    </bean> 
注意中间的 2 。



6
0
查看评论

java.lang.ClassNotFoundException: org.springframework.http.converter.json.MappingJacksonHttpMessageC

spring MVC使用JSON时报异常:  java.lang.ClassNotFoundException: org.springframework.http.converter.json.MappingJacksonHttpMessageConverter 参考博...
  • yixiaoping
  • yixiaoping
  • 2015-04-26 03:06
  • 15305

java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener错误解决方案

在myeclipse自带的tomcat中加载一个web工程,启动tomcat出现java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener错误。一般出现这种错误有可能是spring库没...
  • imlmy
  • imlmy
  • 2013-01-17 14:54
  • 92195

org.springframework.http.converter.json.MappingJacksonHttpMessageConverter

1、错误描述严重: Servlet /huxs threw load() exception java.lang.ClassNotFoundException: org.springframework.http.converter.json.MappingJacksonHttpMessageConv...
  • you23hai45
  • you23hai45
  • 2016-01-13 20:51
  • 7805

java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoader

在使用eclipse进行整合springmvc时经常会碰到这样的异常: java.lang.ClassNotFoundException:org.springframework.web.context.ContextLoaderListener 这时里的意思是说找不到jar包,如果使用的...
  • linzhichao12345
  • linzhichao12345
  • 2015-01-22 17:43
  • 2095

使用JSON报的一个错误java.lang.ClassNotFoundException

2010-09-27 使用JSON报的一个错误java.lang.ClassNotFoundException JavajsonApache java.lang.ClassNotFoundException: org.apache.commons.lang.exc
  • zelda002
  • zelda002
  • 2011-08-17 17:15
  • 1744

java.lang.ClassNotFoundException: org.json.JSONException一种解决方案

已经将json-org-jar导入工程,可是在tomcat启动的时候一直报这个错误。 解决方法:将json-org.jar复制粘贴到tomcat的lib文件夹下。
  • Squeen_
  • Squeen_
  • 2015-06-09 12:27
  • 1830

用JSON报的一个错误java.lang.ClassNotFoundException: org.apache.commons.lang.exception.NestableRuntimeExcept

以前在做项目的时候就曾接触过JSON的技术,但那个时候是项目经理把所有该配制的都配了,工具类也提供了,如何使用也跟我们说了,那个时候只是觉得很好用,倒没有研究过。       今天自己写了一个JSON的例子,可以一调用就出了问题,报下面这个异常: ...
  • eilent
  • eilent
  • 2011-11-02 11:05
  • 17574

java.lang.ClassNotFoundException: net.sf.json.JSONObject

先去检查依赖包的问题 使用net.sf.json需要导入的包如果jar 文件都存在。 右键项目选择Build path 在develoyment Assembly 添加 maven dependencies 网友回答1: 我已经导入了json的jar包及其需要的依赖包,过程是:右键项目...
  • wochunyang
  • wochunyang
  • 2016-05-09 12:46
  • 5558

java.lang.ClassNotFoundException: net.sf.json.JSONArray错误

已经在build path中添加过json-lib-2.1-jdk15.jar,ezmorph-1.0.6.jar依然不行 原因是由于试用开发环境的Build Path导入JSON需要用的Jar,发现这样不行。 解决办法:手动将需要的Jar拷贝到lib目录下。或者部署到tomcat中去。
  • walt18
  • walt18
  • 2014-03-16 17:48
  • 3200

java.lang.ClassNotFoundException: org.codehaus.jackson.JsonProcessingException 异常解决方案

问题: 在SpringMVC中使用Jackson实现json输出时配置如下: text/plain;charset=UTF-8 ...
  • p_3er
  • p_3er
  • 2014-08-22 22:42
  • 15622
    个人资料
    • 访问:185918次
    • 积分:2417
    • 等级:
    • 排名:第18096名
    • 原创:74篇
    • 转载:9篇
    • 译文:6篇
    • 评论:46条
    博客专栏
    最新评论