配置问题:spring-security-web类不可用.您需要使用<filter-chain-map>

Nim*_*sky 7 java spring junit4 maven

我正在尝试使用Maven在我的春季网络应用程序上运行一些单元测试.该应用程序安装并运行正常,它生成一个可部署的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 {
...
Run Code Online (Sandbox Code Playgroud)

但是我收到了错误:

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]
Run Code Online (Sandbox Code Playgroud)

跑步时 Maven > test

我的pom依赖被定义为

<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>3.0.5.RELEASE</version>                
</dependency>
Run Code Online (Sandbox Code Playgroud)

哪个默认为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"/>
Run Code Online (Sandbox Code Playgroud)

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

小智 15

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

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>{version}</version>
        <scope>provided</scope>
    </dependency>
Run Code Online (Sandbox Code Playgroud)


bng*_*n82 13

这是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>
Run Code Online (Sandbox Code Playgroud)