Java Spring安全性-无法访问ServletException

Java Spring安全性-无法访问ServletException,java,spring,security,spring-mvc,spring-security,Java,Spring,Security,Spring Mvc,Spring Security,我喜欢使用spring安全模块,但当我遵循spring项目的教程()时,编译器返回以下内容: [ERROR] COMPILATION ERROR : [INFO] ------------------------------------------------------------- [ERROR] \springframework\security\samples\config\SecurityWebApplicationInitializer.java:[5,7] error: cann

我喜欢使用spring安全模块,但当我遵循spring项目的教程()时,编译器返回以下内容:

[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] \springframework\security\samples\config\SecurityWebApplicationInitializer.java:[5,7] error: cannot access ServletException
[ERROR]\springframework\security\samples\config\SecurityConfig.java:[10,7] error: cannot access Filter
[INFO] 2 errors 
你能告诉我怎么了吗

<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/maven-v4_0_0.xsd"
        >
    <modelVersion>4.0.0</modelVersion>
    <groupId>***</groupId>
    <artifactId>***</artifactId>
    <packaging>war</packaging>
    <version>0.1</version>
    <name>Spring MVC Application</name>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>${project.build.sourceEncoding}</project.reporting.outputEncoding>
        <java-version>1.7</java-version>
        <org.aspectj-version>1.7.4</org.aspectj-version>
        <org.slf4j-version>1.7.5</org.slf4j-version>
        <ch.qos.logback-version>1.0.13</ch.qos.logback-version>
        <org.thymeleaf-version>2.1.2.RELEASE</org.thymeleaf-version>
        <org.thymeleaf.extras.springsecurity3-version>2.1.1.RELEASE</org.thymeleaf.extras.springsecurity3-version>
        <springframework.org-version>4.0.6.RELELASE</springframework.org-version>
    </properties>
    <repositories>
        <repository>
            <id>java.net2</id>
            <name>Repository hosting the jee6 artifacts</name>
            <url>http://download.java.net/maven/2</url>
        </repository>
        <repository>
            <id>sonatype-oss-repository</id>
            <url>https://oss.sonatype.org/content/groups/public/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>repository.spring.milestone</id>
            <name>Spring Milestone Repository</name>
            <url>http://repo.spring.io/milestone</url>
        </repository>
    </repositories>
    <dependencies>
        <!-- Spring -->
        <dependency>
            <groupId>org.springframework</groupId>
            <version>4.0.6.RELEASE</version>
            <artifactId>spring-context</artifactId>
            <exclusions>
                <!-- Exclude Commons Logging in favor of SLF4j -->
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
                    <version>4.0.6.RELEASE</version>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
        </dependency>
        <!-- Security -->
        <dependency>
                    <version>3.2.4.RELEASE</version>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-config</artifactId>
        </dependency>
        <dependency>
                    <version>3.2.4.RELEASE</version>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-web</artifactId>
        </dependency>

    <!-- View -->
    <dependency>
        <groupId>org.thymeleaf</groupId>
        <artifactId>thymeleaf</artifactId>
        <version>${org.thymeleaf-version}</version>
    </dependency>
    <dependency>
        <groupId>org.thymeleaf</groupId>
        <artifactId>thymeleaf-spring4</artifactId>
    </dependency>
    <dependency>
        <groupId>org.thymeleaf.extras</groupId>
        <artifactId>thymeleaf-extras-springsecurity3</artifactId>
        <version>${org.thymeleaf.extras.springsecurity3-version}</version>
    </dependency>
    <!-- Persistence -->
    <dependency>
                <version>4.0.6.RELEASE</version>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jdbc</artifactId>
    </dependency>
    <dependency>
                <version>4.0.6.RELEASE</version>
        <groupId>org.springframework</groupId>
        <artifactId>spring-tx</artifactId>
    </dependency>
    <dependency>
                <version>4.0.6.RELEASE</version>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
    </dependency>

    <!-- Spring Data -->
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-jpa</artifactId>
        <version>1.4.1.RELEASE</version>
    </dependency>

    <!-- AspectJ -->
    <dependency>
        <groupId>org.aspectj</groupId>
        <artifactId>aspectjrt</artifactId>
        <version>${org.aspectj-version}</version>
    </dependency>
    <!-- Logging -->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>${org.slf4j-version}</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>jcl-over-slf4j</artifactId>
        <version>${org.slf4j-version}</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
        <version>${ch.qos.logback-version}</version>
    </dependency>
    <!-- @Inject -->
    <dependency>
        <groupId>javax.inject</groupId>
        <artifactId>javax.inject</artifactId>
        <version>1</version>
    </dependency>
    <!-- JSON -->
    <dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-mapper-asl</artifactId>
        <version>1.9.9</version>
    </dependency>
    <!-- Utilities -->
    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>14.0.1</version>
    </dependency>
    <!-- Test -->
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.11</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.mockito</groupId>
        <artifactId>mockito-core</artifactId>
        <version>1.9.5</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.assertj</groupId>
        <artifactId>assertj-core</artifactId>
        <version>1.5.0</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.hamcrest</groupId>
        <artifactId>hamcrest-core</artifactId>
        <version>1.3</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.hamcrest</groupId>
        <artifactId>hamcrest-library</artifactId>
        <version>1.3</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.objenesis</groupId>
        <artifactId>objenesis</artifactId>
        <version>1.3</version>
        <scope>test</scope>
    </dependency>
    <dependency>
                <version>4.0.6.RELEASE</version>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.apache.tomcat</groupId>
        <artifactId>tomcat-dbcp</artifactId>
        <version>8.0.3</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>4.3.4.Final</version>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.29</version>
    </dependency>


</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-maven-plugin</artifactId>
            <version>2.2</version>
            <configuration>
                <url>http://localhost:8080/manager/text</url>
                <server>localhost</server>
                <path>/coco</path>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>${java-version}</source>
                <target>${java-version}</target>
                <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.1.1</version>
            <configuration>
                <warName>cocoadm-0.1</warName>
                <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <id>install</id>
                    <phase>install</phase>
                    <goals>
                        <goal>sources</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.5</version>
            <configuration>
                <encoding>${project.build.sourceEncoding}</encoding>
            </configuration>
        </plugin>
    </plugins>
</build>
<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.thymeleaf</groupId>
            <artifactId>thymeleaf-spring4</artifactId>
            <version>${org.thymeleaf-version}</version>
        </dependency>
    </dependencies>
</dependencyManagement>

4.0.0
***
***
战争
0.1
SpringMVC应用程序
UTF-8
${project.build.sourceEncoding}
1.7
1.7.4
1.7.5
1.0.13
2.1.2.1发布
2.1.1.1发布
4.0.6.1
java.net2
托管jee6工件的存储库
http://download.java.net/maven/2
sonatype oss存储库
https://oss.sonatype.org/content/groups/public/
真的
真的
repository.spring.milestone
Spring里程碑存储库
http://repo.spring.io/milestone
org.springframework
4.0.6.1发布
spring上下文
公用记录
公用记录
4.0.6.1发布
org.springframework
SpringWebMVC
3.2.4.1发布
org.springframework.security
spring安全配置
3.2.4.1发布
org.springframework.security
spring安全网
org.thymeleaf
百里香
${org.thymeleaf版本}
org.thymeleaf
百里香
org.thymeleaf.extras
thymeleaf-extras-springsecurity3
${org.thymeleaf.extras.springsecurity3版本}
4.0.6.1发布
org.springframework
SpringJDBC
4.0.6.1发布
org.springframework
德克萨斯州春季
4.0.6.1发布
org.springframework
春季甲虫
org.springframework.data
spring数据jpa
1.4.1.1发布
org.aspectj
aspectjrt
${org.aspectj版本}
org.slf4j
slf4j api
${org.slf4j版本}
org.slf4j
jcl-over-slf4j
${org.slf4j版本}
运行时
回写
回归经典
${ch.qos.logback版本}
javax.inject
javax.inject
1.
org.codehaus.jackson
杰克逊地图绘制者
1.9.9
番石榴
番石榴
14.0.1
朱尼特
朱尼特
4.11
测试
org.mockito
莫基托磁芯
1.9.5
测试
org.assertj
assertj核心
1.5.0
测试
org.hamcrest
汉克雷斯特岩芯
1.3
测试
org.hamcrest
汉克雷斯特图书馆
1.3
测试
org.objenesis
正视
1.3
测试
4.0.6.1发布
org.springframework
弹簧试验
测试
org.apache.tomcat
TomcatDBCP
8.0.3
org.hibernate
冬眠核心
4.3.4.最终版本
mysql
mysql连接器java
5.1.29
org.apache.tomcat.maven
tomcat7 maven插件
2.2
http://localhost:8080/manager/text
本地服务器
/可可
org.apache.maven.plugins
maven编译器插件
2.3.2
${java版本}
${java版本}
假的
org.apache.maven.plugins
maven战争插件
2.1.1
cocoadm-0.1
假的
org.apache.maven.plugins
maven依赖插件
安装
安装
来源
org.apache.maven.plugins
maven资源插件
2.5
${project.build.sourceEncoding}
org.thymeleaf
百里香
${org.thymeleaf版本}

尝试添加依赖项

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

javax.servlet
javax.servlet-api
3.1.0
假如

如果您的项目是spring boot,请添加以下内容:

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

org.springframework.boot
SpringBootStarterWeb

是的,这就是原因。谢谢:)注意:我在
构建路径中添加了
tomcat8.0
作为
服务器运行时
。尽管eclipse没有抱怨这样的错误,但在命令行中运行
mvnverify
仍然会报告此错误。无论如何,在
pom.xml
中显式添加此依赖项可以解决问题。这将引入
servlet api
。所以mavarazy是正确的答案。因为您不能总是介绍
spring boot starter web
。例如,您在一个SpringCloudGateway项目中,事实上,CloudGateway使用Webflux(Netty),SpringBootWeb使用Tomcat,这两种方法无法协同工作