简体   繁体   English

JavaConfig:无法解析类型 javax.servlet.ServletContext 和 javax.servlet.ServletException

[英]JavaConfig : The type javax.servlet.ServletContext and javax.servlet.ServletException cannot be resolved

create my first project in Spring and I have some problem.在 Spring 创建我的第一个项目,我遇到了一些问题。 I use JavaConfig to configuration my project and when I start I have this error:我使用 JavaConfig 配置我的项目,当我开始时出现此错误:

Error:(6, 8) java: cannot access javax.servlet.ServletException
class file for javax.servlet.ServletException not found

I now I have to add javax.servlet api but I do not know where to do it.我现在必须添加 javax.servlet api 但我不知道在哪里做。 I create my project in IntelliJ Ultimate 2017.我在 IntelliJ Ultimate 2017 中创建我的项目。

It seems like you haven't included the javax.servlet.jar library in your project. 好像您的项目中没有包含javax.servlet.jar库。

If you're not using any dependency managers, you should add 'javax.servlet.jar' file to your classpath manually with Intellij IDEA: Project Structure (Ctrl+Alt+Shift+S) -> Libraries -> New Project Library -> Java. 如果不使用任何依赖项管理器,则应使用Intellij IDEA将“ javax.servlet.jar”文件手动添加到类路径中:项目结构(Ctrl + Alt + Shift + S)->库->新项目库-> Java。 This jar-file can be downloaded here: http://central.maven.org/maven2/javax/servlet/javax.servlet-api/3.0.1/javax.servlet-api-3.0.1.jar 可以在以下位置下载此jar文件: http : //central.maven.org/maven2/javax/servlet/javax.servlet-api/3.0.1/javax.servlet-api-3.0.1.jar

If you're using Maven, then just add this dependency to maven pom.xml file. 如果您使用的是Maven,则只需将此依赖项添加到maven pom.xml文件。

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.1.0</version>
    <scope>provided</scope>
 </dependency>

ran into a similar problem, I already had a dependency implemented遇到了类似的问题,我已经实现了一个依赖项

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>4.0.1</version>
    <scope>provided</scope>
</dependency>

However, the problem was solved by changing the version of但是,通过更改版本解决了问题

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>6.0.4</version>
</dependency>

to:到:

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>5.2.9.RELEASE</version>
</dependency>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM