java.lang.NoSuchMethodError: 'org.springframework.http.HttpStatus org.springframework.http.client.ClientHttpResponse.getStatusCode()'

huangapple go评论79阅读模式
英文:

java.lang.NoSuchMethodError: 'org.springframework.http.HttpStatus org.springframework.http.client.ClientHttpResponse.getStatusCode()'

问题

我已将Spring Boot版本从2.7.5升级到3.0.2,同时也升级了Jakarta。只有在尝试获取URL时才出现以下错误:

java.lang.NoSuchMethodError: 'org.springframework.http.HttpStatus org.springframework.http.client.ClientHttpResponse.getStatusCode()'
at org.springframework.security.oauth2.client.http.OAuth2ErrorHandler.hasError(OAuth2ErrorHandler.java:76) ~[spring-security-oauth2-2.0.17.RELEASE.jar:na]
...

对于这个错误,你应该检查你的项目中使用的库和依赖项是否与Spring Boot 3.0.2 兼容。这个错误似乎与org.springframework.http.client.ClientHttpResponsegetStatusCode()方法有关,可能是因为版本冲突或旧的依赖项导致的。

要解决这个问题,你可以尝试以下步骤:

  1. 确保你的项目中使用的所有库和依赖项都已升级到与Spring Boot 3.0.2 兼容的版本。

  2. 检查你的项目的pom.xmlbuild.gradle文件,确保没有旧版本的Spring相关依赖项残留。

  3. 通过清除项目的Maven或Gradle缓存并重新构建来确保依赖项已正确升级。

  4. 检查你的代码,确保没有自定义的依赖项冲突或不一致性。

如果你仍然遇到问题,你可能需要查看Spring Boot 3.0.2的文档,以了解关于特定依赖项和配置的更改,以确保你的应用程序正确配置。

英文:

I have updated spring boot version from 2.7.5 to 3.0.2 . I have updated Jakarta too . Only when trying to fatch url it is getting following error:

java.lang.NoSuchMethodError: 'org.springframework.http.HttpStatus org.springframework.http.client.ClientHttpResponse.getStatusCode()'
at org.springframework.security.oauth2.client.http.OAuth2ErrorHandler.hasError(OAuth2ErrorHandler.java:76) \~\[spring-security-oauth2-2.0.17.RELEASE.jar:na\]
at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:904) \~\[spring-web-6.0.4.jar:6.0.4\]
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:864) \~\[spring-web-6.0.4.jar:6.0.4\]
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:804) \~\[spring-web-6.0.4.jar:6.0.4\]
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:665) \~\[spring-web-6.0.4.jar:6.0.4\]
at com.mbusa.gm.repository.OneApiRepository.getVehicleFromSWT(OneApiRepository.java:178) \~\[classes/:na\]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) \~\[na:na\]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) \~\[na:na\]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) \~\[na:na\]
at java.base/java.lang.reflect.Method.invoke(Method.java:568) \~\[na:na\]
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:343) \~\[spring-aop-6.0.4.jar:6.0.4\]
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:196) \~\[spring-aop-6.0.4.jar:6.0.4\]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) \~\[spring-aop-6.0.4.jar:6.0.4\]
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:752) \~\[spring-aop-6.0.4.jar:6.0.4\]
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:137) \~\[spring-tx-6.0.4.jar:6.0.4\]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184) \~\[spring-aop-6.0.4.jar:6.0.4\]
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:752) \~\[spring-aop-6.0.4.jar:6.0.4\]
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:703) \~\[spring-aop-6.0.4.jar:6.0.4\]
at com.mbusa.gm.repository.OneApiRepository$$SpringCGLIB$$0.getVehicleFromSWT(\<generated\>) \~\[classes/:na\]
at com.mbusa.gm.service.GreyMarketService.addVehicleExport(GreyMarketService.java:47) \~\[classes/:na\]
at com.mbusa.gm.controller.GreyMarketController.addVehicleExport(GreyMarketController.java:98) \~\[classes/:na\]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) \~\[na:na\]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) \~\[na:na\]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) \~\[na:na\]
at java.base/java.lang.reflect.Method.invoke(Method.java:568) \~\[na:na\]
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:207) \~\[spring-web-6.0.4.jar:6.0.4\]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:152) \~\[spring-web-6.0.4.jar:6.0.4\]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:117) \~\[spring-webmvc-6.0.4.jar:6.0.4\]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:884) \~\[spring-webmvc-6.0.4.jar:6.0.4\]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:797) \~\[spring-webmvc-6.0.4.jar:6.0.4\]
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) \~\[spring-webmvc-6.0.4.jar:6.0.4\]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1080) \~\[spring-webmvc-6.0.4.jar:6.0.4\]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:973) \~\[spring-webmvc-6.0.4.jar:6.0.4\]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1011) \~\[spring-webmvc-6.0.4.jar:6.0.4\]
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:914) \~\[spring-webmvc-6.0.4.jar:6.0.4\]
at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:731) \~\[tomcat-embed-core-10.1.5.jar:6.0\]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:885) \~\[spring-webmvc-6.0.4.jar:6.0.4\]
at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:814) \~\[tomcat-embed-core-10.1.5.jar:6.0\]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:223) \~\[tomcat-embed-core-10.1.5.jar:10.1.5\]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:158) \~\[tomcat-embed-core-10.1.5.jar:10.1.5\]
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) \~\[tomcat-embed-websocket-10.1.5.jar:10.1.5\]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:185) \~\[tomcat-embed-core-10.1.5.jar:10.1.5\]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:158) \~\[tomcat-embed-core-10.1.5.jar:10.1.5\]
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) \~\[spring-web-6.0.4.jar:6.0.4\]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) \~\[spring-web-6.0.4.jar:6.0.4\]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:185) \~\[tomcat-embed-core-10.1.5.jar:10.1.5\]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:158) \~\[tomcat-embed-core-10.1.5.jar:10.1.5\]
at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) \~\[spring-web-6.0.4.jar:6.0.4\]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) \~\[spring-web-6.0.4.jar:6.0.4\]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:185) \~\[tomcat-embed-core-10.1.5.jar:10.1.5\]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:158) \~\[tomcat-embed-core-10.1.5.jar:10.1.5\]
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) \~\[spring-web-6.0.4.jar:6.0.4\]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) \~\[spring-web-6.0.4.jar:6.0.4\]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:185) \~\[tomcat-embed-core-10.1.5.jar:10.1.5\]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:158) \~\[tomcat-embed-core-10.1.5.jar:10.1.5\]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:177) \~\[tomcat-embed-core-10.1.5.jar:10.1.5\]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97) \~\[tomcat-embed-core-10.1.5.jar:10.1.5\]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:542) \~\[tomcat-embed-core-10.1.5.jar:10.1.5\]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:119) \~\[tomcat-embed-core-10.1.5.jar:10.1.5\]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) \~\[tomcat-embed-core-10.1.5.jar:10.1.5\]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78) \~\[tomcat-embed-core-10.1.5.jar:10.1.5\]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:357) \~\[tomcat-embed-core-10.1.5.jar:10.1.5\]
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:400) \~\[tomcat-embed-core-10.1.5.jar:10.1.5\]
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) \~\[tomcat-embed-core-10.1.5.jar:10.1.5\]
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:859) \~\[tomcat-embed-core-10.1.5.jar:10.1.5\]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1734) \~\[tomcat-embed-core-10.1.5.jar:10.1.5\]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52) \~\[tomcat-embed-core-10.1.5.jar:10.1.5\]
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191) \~\[tomcat-embed-core-10.1.5.jar:10.1.5\]
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659) \~\[tomcat-embed-core-10.1.5.jar:10.1.5\]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) \~\[tomcat-embed-core-10.1.5.jar:10.1.5\]
at java.base/java.lang.Thread.run(Thread.java:833) \~\[na:na\]

What should i update or change for this error?

答案1

得分: 6

你已经进行了一个主要版本的跃迁,从spring-boot 2.X到spring-boot 3.X - 你必须预期会有不兼容的更改。现在,这个有问题的方法已经改变了返回值,查看源代码。我认为问题很明显 - 在JVM字节码中,你有一个方法的版本具有不同的签名,而不是你期望的(注意,对于JVM来说,返回类型是调用指令的一部分并且是签名的一部分):

  1. 在编译时和运行时,你的spring-web JAR包不同。这可能会发生,甚至在计算机科学中有一个叫做依赖地狱的概念。因为这种返回类型的更改是不兼容的,所以你的代码甚至不应该编译通过,但你仍然能够这样做。你需要确保你的编译类路径与运行时类路径具有相同的spring-web JAR包。

  2. 你的代码已经使用旧版本的spring-web编译,现在你正在启动一个提供了较新版本的spring-web类路径的JAR包。虽然不太可能,但仍然值得一提。

最后,有一些很好的文章阐述了你遇到的问题。考虑看一看。

英文:

You have made a major version jump, from spring-boot 2.X to spring-boot 3.X - you must expect that there will be incompatible changes. Now this offending method has changed the return value, check the source. I think the problem is clear - in JVM bytecode you have a versions of the method with different signatures than you expect (Note, that for JVM return type is a part of the invoke instruction and is a part of signature):

  1. You have different spring-web JARs during your compilation and runtime. It can happen, there is even a concept in CS called dependencies hell. Because this return types change is incompatible so your code shouldn't even compile, but still you was able to do so. You need to ensure that your compilation classpath has the same spring-web jar as runtime classpath.

  2. You have code that is already compiled with old spring-web verison, and now you are launching a jar providing a classpath with newer version of spring-web. It is unlikely, but still, worth mentioning.

Finally, there are some good articles that illustrate the problem that you encountered. Consider taking a look.

答案2

得分: 0

只有英文文本需要翻译,以下是翻译结果:

I was in the same situation, and needed code that could work with both Spring Boot 2 and 3.
如果是这种情况,最简单的解决方案是使用(现在已经弃用)方法getStatusCodeValue(),这在spring-web 4.x到6.x中都可以工作(它返回一个整数值而不是字符串,但你应该能够处理)。

Mind you, there have been lots of other incompatible changes (a ton more than there were between spring-web 4.x and 5.x) so you might still encounter problems...

英文:

I was in the same situation, and needed code that could work with both Spring Boot 2 and 3.
If that's your case, the simplest solution is to use instead the (now deprecated) method getStatusCodeValue() this will work the same in spring-web from 4.x to 6.x (it returns an int value instead of a String, but you should be able to manage that).

Mind you, there have been lots of other incompatible changes (a ton more than there were between spring-web 4.x and 5.x) so you might still encounter problems...

huangapple
  • 本文由 发表于 2023年2月10日 14:49:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/75407765.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定