私は自分のWebプロジェクトにSpring Securityを含めようとしています。このチュートリアルhttp://docs.spring.io/spring-security/site/docs/current/guides/html5//helloworld.htmlに従っています
私は与えられたmavenプロジェクトでチュートリアルのすべてを実行しましたが、うまくいきます。しかし、それをプロジェクトに含めようとすると、コンパイルエラーが表示されます。具体的には、iが拡張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を使用する
javax.servlet
APIをコンパイル時の依存関係に追加するだけです。ビルドに含める必要はありません。ターゲットサーブレットコンテナによってすでに提供されています。
Your current pom suggests that you're deploying to a barebones servlet container (Tomcat, Jetty, etc) instead of a full fledged Java EE application server (WildFly, TomEE, GlassFish, Liberty, etc), otherwise you'd have run into classloading-related trouble by providing JSF along with the webapp instead of using the container-provided one.
In that case, adding the below dependency should do for a Servlet 3.1 container 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're actually targeting an older Servlet 3.0 container like Tomcat 7, change the <version>
to 3.0.1
(note: there's no 3.0
due to a mistake on their side).
WildFly 8などのJava EE 7アプリケーションサーバーに実際にデプロイする場合は、代わりに以下の依存関係を使用してください。これには、以下を含むJava EE API全体が含まれますjavax.servlet
(javax.faces
そのため、これらの個々のJSF API / impl依存関係を削除します)。
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
また、ここでは、JBoss AS 7などの古いJava EE 6アプリケーションサーバーを対象としている場合は、をに変更<version>
し6.0
ます。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加