轉載:Spring整合JSON報錯:java.lang.ClassNotFoundException: org.codehaus.jackson.JsonProcessingException
轉載:https://blog.csdn.net/jiaotuwoaini/article/details/52366057
先看異常資訊:
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 。相關文章
- 菜鳥調錯(四)——Spring與DWR整合,配置檔案報錯Spring
- Spring Boot整合Swagger報錯:"this.condition" is nullSpring BootSwaggerNull
- Spring整合Mybatis時Mapper代理報錯BindingExceptionSpringMyBatisAPPException
- spring json dwr struts2.0 hibernate整合SpringJSON
- mysql 報錯json字串 中文漢字轉義的問題MySqlJSON字串
- fastjson 返回json字串,JSON.parse 報錯ASTJSON字串
- spring ehcache報錯Spring
- 謹以此錯誤警醒自己---java.lang.ClassNotFoundException:JavaException
- Spring報錯彙總Spring
- springboot整合mina報錯Spring Boot
- JSON 資料型別(轉載)JSON資料型別
- 理解spring (轉載)Spring
- python解析json檔案報錯No JSON object could be decodedPythonJSONObject
- json-lib系列包報錯原因JSON
- 解析帶有反斜槓的json報文報錯JSON
- maven專案 啟動報錯:java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListenerMavenJavaExceptionSpringFrameworkWebContext
- spring學習(轉載)Spring
- java.lang.ClassNotFoundExceptionJavaException
- Spring Cloud Gateway 整合Eureka路由轉發SpringCloudGateway路由
- Spring Boot整合Hystrix實現服務容錯Spring Boot
- spring引入properties變數報錯Spring變數
- Spring Boot之自定義JSON轉換器Spring BootJSON
- Web開發, 跳轉時出現java.lang.ClassNotFoundExceptionWebJavaException
- 【轉載】Spring Cache介紹Spring
- 【轉載】spring框架介紹Spring框架
- 部署Maven專案到tomcat報錯:java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderLi...MavenTomcatJavaExceptionSpringFrameworkWebContext
- Struts2+hibernate+spring配置程式整合下載Spring
- 關於新浪雲JSON.parse報錯的問題JSON
- Spring Jar包因為JDK版本報錯SpringJARJDK
- [轉載]uiautomator埠除錯UI除錯
- .ui轉.py檔案報錯UI
- Spring Boot整合Spring BatchSpring BootBAT
- Spring Boot整合Spring SecuritySpring Boot
- Spring Boot整合Spring AopSpring Boot
- Spring 整合 MyBatisSpringMyBatis
- mybatis整合springMyBatisSpring
- ActiveMq整合SpringMQSpring
- Spring整合MyBatisSpringMyBatis