配置问题:spring-security-web 类不可用。您需要这些才能使用

发布于 2024-12-04 11:29:48 字数 1679 浏览 0 评论 0原文

我正在尝试使用 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范围,哪个应该没问题?当我将范围更改为 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"/>

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

樱娆 2024-12-11 11:29:48

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

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

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

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>{version}</version>
        <scope>provided</scope>
    </dependency>
叹梦 2024-12-11 11:29:48

这是 Spring Security 的一个 bug。将 Spring Security Web 包含到您的 pom.xml 中。

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

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

<dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-web</artifactId>
    <version>3.0.5.RELEASE</version>
</dependency>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文