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
Configuration problem: spring-security-web classes are not available. You need these to use <filter-chain-map>
提问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 compile
scope, which should be OK? It returns the same error when I change scope to test
and provided
.
哪个默认为compile
范围,哪个应该没问题?当我将范围更改为test
and时,它返回相同的错误provided
。
And my .classpath
looks 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>