java - 通过maven 导入servlet-api 中ServletRequest.getServletContext无法找到

查看:129
本文介绍了java - 通过maven 导入servlet-api 中ServletRequest.getServletContext无法找到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

一、通过maven导入servelt-api 在使用 HttpServletRequest.getServletContext 方法时IDEA提示没有找到相应方法,通过映射至源码发现确实没有,如下图

pom.xml配置

<dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>servlet-api</artifactId>
      <version>3.0-alpha-1</version>
</dependency>

Tomcat 及JDK

二、通过修改servlet-api依赖至本地Tomcat/lib中的jar包问题不存在

三、问是不是通过maven引入的jar包与tomcat/lib中的jar不一样??

解决方案

将你的maven依赖改为即可解决问题:

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.0.1</version>
</dependency>

在web项目中,tomcat会自带servlet容器,所以,为了防止冲突,往往会在依赖中加入

<scope>provided</scope>

这篇关于java - 通过maven 导入servlet-api 中ServletRequest.getServletContext无法找到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆