【发布时间】:2015-08-24 14:24:15
【问题描述】:
我正在尝试将 Spring Security 包含到我的 Web 项目中,我正在关注本教程 http://docs.spring.io/spring-security/site/docs/current/guides/html5//helloworld.html
我已经使用给定的 maven 项目完成了教程中的所有内容,并且工作正常。但是当我试图将它包含到我的项目中时,会出现编译错误。特别是当我从AbstractSecurityWebApplicationInitializer 扩展时出现给定错误
这一行有多个标记
- 类型 javax.servlet.ServletContext 无法解析。它是从所需的 .class 文件中间接引用的
- javax.servlet.ServletException 类型无法解析。它是从所需的 .class 文件中间接引用的
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>
感谢您的帮助!
使用 mvn clean install -U
【问题讨论】:
-
如果没有 pom 的相关部分,就很难诊断。
-
抱歉,我刚刚上传了完整的 pom。
-
从命令提示符执行命令(从保存 POM 的目录执行)。 mvn 干净安装 -U。如果这不起作用,请检查存储库路径的 apache-maven-3.3.1\conf\settings.xml 文件
-
@Vinayak 我只是在检查设置文件,但是存储库路径在哪里/是什么?
-
SprintBoot App 发现同样的错误,当默认情况下 pom 中的 spring boot 启动器依赖项并且仍然要求 ServletContex 时,这很奇怪
标签: java maven servlets spring-security