Type javax servlet. ServletContext and javax servlet. ServletException cannot be resolved
I'm trying to include spring security in my web project, and I'm following this tutorial http://docs.spring.io/spring-security/site/docs/current/guides/html5//helloworld.html
I have completed the given Maven project in the tutorial and it works normally But when I try to include it in my project, a compilation error occurs Specifically, when I extend from abstractsecuritywebapplicationinitializer, a given error occurs
POM. xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>spring.primefaces</groupId> <artifactId>primefaces.testwebapp</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <name>SpringPrimefacesWebApp</name> <build> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.7</source> <target>1.7</target> </configuration> </plugin> <plugin> <artifactId>maven-war-plugin</artifactId> <version>2.3</version> <configuration> <failOnMissingWebXml>false</failOnMissingWebXml> </configuration> </plugin> </plugins> </build> <dependencies> <!-- JSF 2.2 core and implementation --> <dependency> <groupId>com.sun.faces</groupId> <artifactId>jsf-api</artifactId> <version>2.2.11</version> </dependency> <dependency> <groupId>com.sun.faces</groupId> <artifactId>jsf-impl</artifactId> <version>2.2.11</version> </dependency> <!-- Prime Faces --> <dependency> <groupId>org.primefaces</groupId> <artifactId>primefaces</artifactId> <version>5.2</version> </dependency> <!-- Spring security --> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-web</artifactId> <version>4.0.1.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-config</artifactId> <version>4.0.1.RELEASE</version> </dependency> </dependencies> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-framework-bom</artifactId> <version>4.1.6.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>
Thank you for your help!
Use MVN clean install - U
Solution
Just put javax Servlet API added to compile - time dependencies You do not need to include it in the build; it is already provided by the target servlet container
Your current POM indicates that you are deploying to the quasi system servlet container (tomcat, jetty, etc.) instead of the complete Java EE application server (wildfly, tomee, GlassFish, liberty, etc.), otherwise you will encounter class loading to solve the problem by providing JSF and webapp instead of using the methods provided by the container
In this case, adding the following dependencies should apply to servlet 3.1 containers like Tomcat 8:
<dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.1.0</version> <scope>provided</scope> </dependency>
Or, if you are actually targeting older servlet 3.0 containers (such as Tomcat 7), change < version > to 3.0 1 (Note: no 3.0, due to the mistakes around them)
If you happen to actually deploy to a Java EE 7 application server like wildfly 8, use the following dependencies instead It covers the entire Java EE API, including javax Servlets (and javax. Faces, so you'll delete those individual JSF API / impl dependencies):
<dependency> <groupId>javax</groupId> <artifactId>javaee-api</artifactId> <version>7.0</version> <scope>provided</scope> </dependency>
In addition, if you want to locate an earlier Java EE 6 application server (such as JBoss as 7), change < version > to 6.0