![](/img/trans.png)
[英]The type javax.servlet.ServletContext and javax.servlet.ServletException cannot be resolved
[英]JavaConfig : The type javax.servlet.ServletContext and javax.servlet.ServletException cannot be resolved
在 Spring 创建我的第一个项目,我遇到了一些问题。 我使用 JavaConfig 配置我的项目,当我开始时出现此错误:
Error:(6, 8) java: cannot access javax.servlet.ServletException
class file for javax.servlet.ServletException not found
我现在必须添加 javax.servlet api 但我不知道在哪里做。 我在 IntelliJ Ultimate 2017 中创建我的项目。
好像您的项目中没有包含javax.servlet.jar
库。
如果不使用任何依赖项管理器,则应使用Intellij IDEA将“ javax.servlet.jar”文件手动添加到类路径中:项目结构(Ctrl + Alt + Shift + S)->库->新项目库-> Java。 可以在以下位置下载此jar文件: http : //central.maven.org/maven2/javax/servlet/javax.servlet-api/3.0.1/javax.servlet-api-3.0.1.jar
如果您使用的是Maven,则只需将此依赖项添加到maven pom.xml文件。
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
遇到了类似的问题,我已经实现了一个依赖项
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
<scope>provided</scope>
</dependency>
但是,通过更改版本解决了问题
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>6.0.4</version>
</dependency>
到:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.2.9.RELEASE</version>
</dependency>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.