简体   繁体   中英

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

create my first project in Spring and I have some problem. I use JavaConfig to configuration my project and when I start I have this error:

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. I create my project in IntelliJ Ultimate 2017.

It seems like you haven't included the javax.servlet.jar library in your project.

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. 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

If you're using Maven, then just add this dependency to maven pom.xml file.

<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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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