java 配置问题:spring-security-web 类不可用。你需要这些来使用 <filter-chain-map>

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7402144/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 19:48:07  来源:igfitidea点击:

Configuration problem: spring-security-web classes are not available. You need these to use <filter-chain-map>

javaspringmavenjunit4

提问by NimChimpsky

I am attempting to run some unit tests on my spring web app using Maven. The app installs and runs fine, it generates a deployable war file all OK (all using Maven).

我正在尝试使用 Maven 在我的 Spring Web 应用程序上运行一些单元测试。该应用程序安装并运行良好,它生成一个可部署的War文件一切正常(全部使用 Maven)。

My test class (located in src/test/java):

我的测试类(位于 src/test/java 中):

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"file:C:/myProjects/myWebapp/src/main/webapp/WEB-INF/applicationContext-test.xml"})
@Transactional
public class MyTest {
...

However I recieve the error :

但是我收到错误:

Configuration problem: spring-security-web classes are not available. You need these to use <filter-chain-map>

Offending resource: URL [file:C:/myProjects/myWebapp/src/main/webapp/WEB-INF/applicationContext-test.xml]

When running Maven > test

跑步时 Maven > test

My pom dependcy is defined as

我的 pom 依赖被定义为

<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>3.0.5.RELEASE</version>                
</dependency>

Which defaults to compilescope, which should be OK? It returns the same error when I change scope to testand provided.

哪个默认为compile范围,哪个应该没问题?当我将范围更改为testand时,它返回相同的错误provided

And my .classpathlooks like this:

我的.classpath样子是这样的:

<classpath>
    <classpathentry kind="src" output="target/classes" path="src/main/java"/>
    <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
    <classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
    <classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>

How do I set-up my app context and tests correctly ?

如何正确设置我的应用程序上下文和测试?

回答by user845199

You have to include the Servlet library in your pom.xml :

您必须在 pom.xml 中包含 Servlet 库:

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

回答by bnguyen82

It's a bugof Spring Security. Include Spring Security Web to your pom.xml.

这是 Spring Security的一个错误。在 pom.xml 中包含 Spring Security Web。

<dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-web</artifactId>
    <version>3.0.5.RELEASE</version>
</dependency>