jjzjj

java - 配置问题 : spring-security-web classes are not available. 你需要这些才能使用 <filter-chain-map>

coder 2024-03-14 原文

我正在尝试使用 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 作用域,which should be OK ?当我将范围更改为 testprovided 时,它返回相同的错误。

我的 .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"/>

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

最佳答案

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

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

关于java - 配置问题 : spring-security-web classes are not available. 你需要这些才能使用 <filter-chain-map>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7402144/

有关java - 配置问题 : spring-security-web classes are not available. 你需要这些才能使用 <filter-chain-map>的更多相关文章

随机推荐