NoClassDefFoundError: Could not initialize class org.springframework.web.client.RestTemplate
来源:互联网 发布:mac终端怎么使用 编辑:程序博客网 时间:2024/06/04 19:18
项目在windows环境下可以正常运行,放到linux系统中访问这个接口就会报错,其他接口都没有问题。org.springframework.web-3.0.6.RELEASE.jar这个jar包我已经放到了正确的路径,但还是报NoClassDefFoundError,注意,不是ClassNotFound,是指编译的时候能正常编译,运行时找不到指定的类,主要问题在于org.springframework.web.client.RestTemplate这个类不能初始化,但是该怎么解决呢,求大神帮忙。以下是异常的详细报告。
exception
java.lang.RuntimeException: javax.servlet.ServletException: org.glassfish.jersey.server.ContainerException: java.lang.NoClassDefFoundError: Could not initialize class org.springframework.web.client.RestTemplatecom.google.common.base.Throwables.propagate(Throwables.java:160)com.xinhunbao.jersey.AppFilter.doFilter(AppFilter.java:85)org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
javax.servlet.ServletException: org.glassfish.jersey.server.ContainerException: java.lang.NoClassDefFoundError: Could not initialize class org.springframework.web.client.RestTemplateorg.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:489)org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:427)org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:388)org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:341)org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:228)com.xinhunbao.jersey.AppFilter.doFilter(AppFilter.java:74)org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
org.glassfish.jersey.server.ContainerException: java.lang.NoClassDefFoundError: Could not initialize class org.springframework.web.client.RestTemplateorg.glassfish.jersey.servlet.internal.ResponseWriter.rethrow(ResponseWriter.java:278)org.glassfish.jersey.servlet.internal.ResponseWriter.failure(ResponseWriter.java:260)org.glassfish.jersey.server.ServerRuntime$Responder.process(ServerRuntime.java:509)org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:334)org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)org.glassfish.jersey.internal.Errors.process(Errors.java:315)org.glassfish.jersey.internal.Errors.process(Errors.java:297)org.glassfish.jersey.internal.Errors.process(Errors.java:267)org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317)org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:305)org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1154)org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:473)org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:427)org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:388)org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:341)org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:228)com.xinhunbao.jersey.AppFilter.doFilter(AppFilter.java:74)org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
经过几天的苦思冥想与尝试,终于找到了问题所在。根源问题在于pom.xml文件中的配置,关于这两个jar包的配置如下:
<dependency> <groupId>com.lala.api</groupId> <artifactId>core</artifactId> <version>3.0.6.RELEASE</version> <scope>system</scope> <systemPath>${basedir}/lib/org.springframework.core-3.0.6.RELEASE.jar</systemPath></dependency><dependency> <groupId>com.lala.api</groupId> <artifactId>web</artifactId> <version>3.0.6.RELEASE</version> <scope>system</scope> <systemPath>${basedir}/lib/org.springframework.web-3.0.6.RELEASE.jar</systemPath></dependency>问题就出在这儿,这样的配置在编译时没有问题,但是使用mvn package打包时报了一个警告:
[WARNING] 'dependencies.dependency.systemPath' for com.lala.api:core:jar should not point at files within the project directory, ${basedir}/lib/org.springframework.core-3.0.6.RELEASE.jar will be unresolvable by dependent projects @ line 240, column 25[WARNING] 'dependencies.dependency.systemPath' for com.lala.api:web:jar should not point at files within the project directory, ${basedir}/lib/org.springframework.web-3.0.6.RELEASE.jar will be unresolvable by dependent projects @ line 248, column 25
意思是说无法通过systemPath的路径在文件夹中定位这两个jar包,所以在tomcat运行后报NoClassDefFoundError。
解决方法如下:找到jar包所在的文件夹lib,运行cmd指令:
mvn install:install-file -Dfile=org.springframework.core-3.0.6.RELEASE.jar -DgroupId=org.springframework -DartifactId=core -Dversion=3.0.6.RELEASE -Dpackaging=jarmvn install:install-file -Dfile=org.springframework.web-3.0.6.RELEASE.jar -DgroupId=org.springframework -DartifactId=web -Dversion=3.0.6.RELEASE -Dpackaging=jar
这样就可以将jar添加到maven本地仓库,然后在pom.xml中配置:
<dependency> <groupId>org.springframework</groupId> <artifactId>core</artifactId> <version>3.0.6.RELEASE</version></dependency><dependency> <groupId>org.springframework</groupId> <artifactId>web</artifactId> <version>3.0.6.RELEASE</version></dependency>然后打包运行服务就可以啦。
终于解决这个困扰我好久的难题,特别开心,哈哈。不敢自专,共飨诸君。
0 0
- NoClassDefFoundError: Could not initialize class org.springframework.web.client.RestTemplate
- 【SpringBoot】RestTemplate调用报错:'org.springframework.web.client.RestTemplate' that could not be found.
- java.lang.NoClassDefFoundError: Could not initialize class org.springframework.beans.factory.BeanCre
- Junit 抛出错误 java.lang.NoClassDefFoundError: Could not initialize class org.springframework.test.conte
- NoClassDefFoundError: Could not initialize class
- Spring org.springframework.web.client.RestTemplate乱码
- java.lang.NoClassDefFoundError: Could not initialize class
- 异常:NoClassDefFoundError或Could not initialize class
- org.apache.cxf.interceptor.Fault: Could not initialize class org.springframework.jdbc.core.Statement
- jboss java.lang.NoClassDefFoundError: Could not initialize class com.documentum.fc.client.DfClient
- java.lang.NoClassDefFoundError: Could not initialize class org.apache.log4j.Log4jLoggerFactory
- java.lang.NoClassDefFoundError: Could not initialize class org.apache.log4j.Log4jLoggerFactory
- java.lang.NoClassDefFoundError: Could not initialize class org.hibernate.validator.internal.engine.m
- java.lang.NoClassDefFoundError: Could not initialize class org.apache.log4j.Log4
- java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.jackson.map.ObjectMapper
- java.lang.NoClassDefFoundError: Could not initialize class org.apache.log4j.Log4
- java.lang.NoClassDefFoundError: Could not initialize class org.apache.log4j.Log4jLoggerFactory
- java.lang.NoClassDefFoundError: Could not initialize class org.apache.log4j.Log4jLoggerFactory
- 用matlab绘制生日蛋糕
- Oracle PL/SQL入门语法点
- Android绘图板
- 信号处理和模式识别方面的MATLAB工具箱
- 调用WebServices传参对方验证为空
- NoClassDefFoundError: Could not initialize class org.springframework.web.client.RestTemplate
- 新的思考
- ThoughtWorks笔试题汇总 2016
- nginx 配置 https
- 解决ie6下兼容float 换行问题,解决ie6下padding的时候 宽度不自动扩展问题
- 对于mock的理解
- Floyd判圈法
- C Looooops poj2115 (扩展欧几里得+模线性方程)
- jq/css鼠标经过图片放大效果