配置问题:spring-security-web 类不可用。您需要这些才能使用
我正在尝试使用 Maven 在我的 Spring Web 应用程序上运行一些单元测试。该应用程序安装并运行良好,它生成了一个可部署的 war 文件,一切正常(全部使用 Maven)。
我的测试类(位于 src/test/java 中):
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"file:C:/myProjects/myWebapp/src/main/webapp/WEB-INF/applicationContext-test.xml"})
@Transactional
public class MyTest {
...
但是我收到错误:
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]
运行 Maven > 时test
我的pom依赖被定义为
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>3.0.5.RELEASE</version>
</dependency>
默认为compile
范围,哪个应该没问题?当我将范围更改为 test
和 provided
时,它会返回相同的错误。
我的 .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 test权利正确?
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).
My test class (located in 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
My pom dependcy is defined as
<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
.
And my .classpath
looks like this:
<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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须在 pom.xml 中包含 Servlet 库:
You have to include the Servlet library in your pom.xml :
这是 Spring Security 的一个 bug。将 Spring Security Web 包含到您的 pom.xml 中。
It's a bug of Spring Security. Include Spring Security Web to your pom.xml.