热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Java中调用`response.getStatus()`方法时遇到`NoSuchMethodError`异常分析与解决

在Java应用程序中调用`response.getStatus()`方法时遇到了`NoSuchMethodError`异常,经过分析,初步判断为依赖冲突问题。通过检查项目依赖树发现,当前项目版本与某些库的版本不兼容,导致该方法无法被正确识别。建议通过更新相关依赖版本或使用依赖管理工具(如Maven或Gradle)来解决此问题,确保所有依赖项版本一致且兼容。

我想这是某种依赖性问题,所以这是我的树:

[INFO] Sikor:BrowserGame:war:1.0-SNAPSHOT

[INFO] +- junit:junit:jar:3.8.1:test

[INFO] +- org.springframework:spring-context:jar:4.1.1.RELEASE:compile

[INFO] | +- org.springframework:spring-aop:jar:4.1.1.RELEASE:compile

[INFO] | +- org.springframework:spring-beans:jar:4.1.1.RELEASE:compile

[INFO] | +- org.springframework:spring-core:jar:4.1.1.RELEASE:compile

[INFO] | | \- commons-logging:commons-logging:jar:1.1.3:compile

[INFO] | \- org.springframework:spring-expression:jar:4.1.1.RELEASE:compile

[INFO] +- org.springframework:spring-webmvc:jar:4.1.1.RELEASE:compile

[INFO] | \- org.springframework:spring-web:jar:4.1.1.RELEASE:compile

[INFO] +- org.springframework:spring-context-support:jar:4.1.1.RELEASE:compile

[INFO] +- org.springframework.security:spring-security-web:jar:3.2.5.RELEASE:compile

[INFO] | +- aopalliance:aopalliance:jar:1.0:compile

[INFO] | \- org.springframework.security:spring-security-core:jar:3.2.5.RELEASE:compile

[INFO] +- org.springframework.security:spring-security-config:jar:3.2.5.RELEASE:compile

[INFO] +- org.springframework.security:spring-security-taglibs:jar:3.2.5.RELEASE:compile

[INFO] | \- org.springframework.security:spring-security-acl:jar:3.2.5.RELEASE:compile

[INFO] +- org.thymeleaf:thymeleaf-spring4:jar:2.1.3.RELEASE:compile

[INFO] | \- org.thymeleaf:thymeleaf:jar:2.1.3.RELEASE:compile

[INFO] | +- ognl:ognl:jar:3.0.6:compile

[INFO] | \- org.unbescape:unbescape:jar:1.0:compile

[INFO] +- org.thymeleaf.extras:thymeleaf-extras-springsecurity3:jar:2.1.1.RELEASE:compile

[INFO] +- nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect:jar:1.2.7:compile

[INFO] +- org.hibernate:hibernate-entitymanager:jar:4.3.5.FINAL:compile

[INFO] | +- org.jboss.logging:jboss-logging:jar:3.1.3.GA:compile

[INFO] | +- org.jboss.logging:jboss-logging-annotations:jar:1.2.0.Beta1:compile

[INFO] | +- org.hibernate:hibernate-core:jar:4.3.5.Final:compile

[INFO] | | +- antlr:antlr:jar:2.7.7:compile

[INFO] | | \- org.jboss:jandex:jar:1.1.0.Final:compile

[INFO] | +- dom4j:dom4j:jar:1.6.1:compile

[INFO] | | \- xml-apis:xml-apis:jar:1.0.b2:compile

[INFO] | +- org.hibernate.common:hibernate-commons-annotations:jar:4.0.4.Final:compile

[INFO] | +- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile

[INFO] | +- org.jboss.spec.javax.transaction:jboss-transaction-api_1.2_spec:jar:1.0.0.Final:compile

[INFO] | \- org.javassist:javassist:jar:3.18.1-GA:compile

[INFO] +- org.hibernate:hibernate-validator:jar:4.3.2.Final:compile

[INFO] | \- javax.validation:validation-api:jar:1.0.0.GA:compile

[INFO] +- mysql:mysql-connector-java:jar:5.1.32:compile

[INFO] +- org.springframework:spring-orm:jar:4.1.1.RELEASE:compile

[INFO] | +- org.springframework:spring-jdbc:jar:4.1.1.RELEASE:compile

[INFO] | \- org.springframework:spring-tx:jar:4.1.1.RELEASE:compile

[INFO] +- org.springframework.data:spring-data-jpa:jar:1.6.4.RELEASE:compile

[INFO] | +- org.springframework.data:spring-data-commons:jar:1.8.4.RELEASE:compile

[INFO] | +- org.aspectj:aspectjrt:jar:1.8.1:compile

[INFO] | \- org.slf4j:jcl-over-slf4j:jar:1.7.7:runtime

[INFO] +- javax.servlet:javax.servlet-api:jar:3.1.0:provided

[INFO] +- org.slf4j:slf4j-api:jar:1.7.5:compile

[INFO] +- org.slf4j:slf4j-log4j12:jar:1.6.1:compile

[INFO] | \- log4j:log4j:jar:1.2.16:compile

[INFO] \- javax.mail:mail:jar:1.4:compile

[INFO] \- javax.activation:activation:jar:1.1:compile

从我发现的结果来看,Spring 4.1.1应该可以与javax.servlet 3.1.0一起使用,但是我在调​​用response.getStatus()时遇到了java.lang.NoSuchMethodError:javax.servlet.http.HttpServletResponse.getStatus() )放在我的拦截器中.

如果有人可以帮忙,我会很高兴.提前致谢.

编辑:添加了web.xml

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

mvc-dispatcher

org.springframework.web.servlet.DispatcherServlet

contextConfigLocation

/WEB-INF/config/mvc-dispatcher-servlet.xml

throwExceptionIfNoHandlerFound

true

1

mvc-dispatcher

/

springSecurityFilterChain

org.springframework.web.filter.DelegatingFilterProxy

springSecurityFilterChain

/*

org.springframework.web.context.ContextLoaderListener

contextConfigLocation

/WEB-INF/config/root-context.xml

EDIT2:更改了以下内容:

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

至:

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"

version="3.1">

但是在调用response.getStatus()时仍然出现错误.

解决方法:

我在一个简单的tomcat:run上运行我的应用程序.将其部署到战争中并确保使用Tomcat 7之后,一切都很好.感谢所有评论员,您为我指明了正确的方向.干杯.

编辑:请记住,tomcat 7不支持servlet 3.1,因此您必须将servlet 3.0与tomcat 7或servlet 3.1和tomcat 8一起使用.

标签:java,spring,servlets,response

来源: https://codeday.me/bug/20191011/1889135.html



推荐阅读
  • 将Web服务部署到Tomcat
    本文介绍了如何在JDeveloper 12c中创建一个Java项目,并将其打包为Web服务,然后部署到Tomcat服务器。内容涵盖从项目创建、编写Web服务代码、配置相关XML文件到最终的本地部署和验证。 ... [详细]
  • 本文深入探讨了HTTP请求和响应对象的使用,详细介绍了如何通过响应对象向客户端发送数据、处理中文乱码问题以及常见的HTTP状态码。此外,还涵盖了文件下载、请求重定向、请求转发等高级功能。 ... [详细]
  • 本文介绍如何使用 Android 的 Canvas 和 View 组件创建一个简单的绘图板应用程序,支持触摸绘画和保存图片功能。 ... [详细]
  • PHP 5.2.5 安装与配置指南
    本文详细介绍了 PHP 5.2.5 的安装和配置步骤,帮助开发者解决常见的环境配置问题,特别是上传图片时遇到的错误。通过本教程,您可以顺利搭建并优化 PHP 运行环境。 ... [详细]
  • RecyclerView初步学习(一)
    RecyclerView初步学习(一)ReCyclerView提供了一种插件式的编程模式,除了提供ViewHolder缓存模式,还可以自定义动画,分割符,布局样式,相比于传统的ListVi ... [详细]
  • 基于KVM的SRIOV直通配置及性能测试
    SRIOV介绍、VF直通配置,以及包转发率性能测试小慢哥的原创文章,欢迎转载目录?1.SRIOV介绍?2.环境说明?3.开启SRIOV?4.生成VF?5.VF ... [详细]
  • 本文探讨了 Spring Boot 应用程序在不同配置下支持的最大并发连接数,重点分析了内置服务器(如 Tomcat、Jetty 和 Undertow)的默认设置及其对性能的影响。 ... [详细]
  • 深入解析 Apache Shiro 安全框架架构
    本文详细介绍了 Apache Shiro,一个强大且灵活的开源安全框架。Shiro 专注于简化身份验证、授权、会话管理和加密等复杂的安全操作,使开发者能够更轻松地保护应用程序。其核心目标是提供易于使用和理解的API,同时确保高度的安全性和灵活性。 ... [详细]
  • 本文介绍如何使用布局文件在Android应用中排列多行TextView和Button,使其占据屏幕的特定比例,并提供示例代码以帮助理解和实现。 ... [详细]
  • PHP 过滤器详解
    本文深入探讨了 PHP 中的过滤器机制,包括常见的 $_SERVER 变量、filter_has_var() 函数、filter_id() 函数、filter_input() 函数及其数组形式、filter_list() 函数以及 filter_var() 和其数组形式。同时,详细介绍了各种过滤器的用途和用法。 ... [详细]
  • Struts与Spring框架的集成指南
    本文详细介绍了如何将Struts和Spring两个流行的Java Web开发框架进行整合,涵盖从环境配置到代码实现的具体步骤。 ... [详细]
  • 本文详细介绍了C++中map容器的多种删除和交换操作,包括clear、erase、swap、extract和merge方法,并提供了完整的代码示例。 ... [详细]
  • 深入解析SpringMVC核心组件:DispatcherServlet的工作原理
    本文详细探讨了SpringMVC的核心组件——DispatcherServlet的运作机制,旨在帮助有一定Java和Spring基础的开发人员理解HTTP请求是如何被映射到Controller并执行的。文章将解答以下问题:1. HTTP请求如何映射到Controller;2. Controller是如何被执行的。 ... [详细]
  • 在编译BSP包过程中,遇到了一个与 'gets' 函数相关的编译错误。该问题通常发生在较新的编译环境中,由于 'gets' 函数已被弃用并视为安全漏洞。本文将详细介绍如何通过修改源代码和配置文件来解决这一问题。 ... [详细]
  • Spring Boot 中静态资源映射详解
    本文深入探讨了 Spring Boot 如何简化 Web 应用中的静态资源管理,包括默认的静态资源映射规则、WebJars 的使用以及静态首页的处理方法。通过本文,您将了解如何高效地管理和引用静态资源。 ... [详细]
author-avatar
1515921251_06a4db
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有