【问题标题】:Spring project error now that I am using Maven现在我正在使用 Maven,出现 Spring 项目错误
【发布时间】:2012-09-05 19:43:56
【问题描述】:

我开始使用 Maven 将我的 JAR 引入我的项目中。我有一个 Spring 项目,我在 Eclipse 中移入了一个 maven 项目,但现在出现此错误:

Description Resource    Path    Location    Type
The classes from the spring-security-web jar (or one of its dependencies) are not available. You need these to use <http>: javax.servlet.Filter my-security-context.xml /WebFlowTemplate/src/main/webapp/WEB-INF/spring line 12 Spring Beans Problem

这是我得到的一条线:

<http use-expressions="true">

这是我的 my-security-context.xml 文件:

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans 
    xmlns="http://www.springframework.org/schema/security"
    xmlns:beans="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
                        http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
                        http://www.springframework.org/schema/security
                        http://www.springframework.org/schema/security/spring-security-3.1.xsd">


    <http use-expressions="true">

        <intercept-url access="hasRole('ROLE_USER')"    pattern="/helloworld**" />
        <intercept-url pattern='/*' access='permitAll' />


        <form-login login-page="/login.jsp"
            authentication-failure-url="/login.jsp" 
            default-target-url="/helloworld" />

        <logout logout-success-url="/" />
    </http>

    <authentication-manager>
        <authentication-provider>
            <user-service>
                <user name="user" password="user" authorities="ROLE_USER" />
            </user-service>

        </authentication-provider>
    </authentication-manager>
</beans:beans>

这是我的 pom.xml 文件。

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.springsource.greenbeans.maven</groupId>
    <artifactId>WebFlowTemplate</artifactId>
    <packaging>war</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <name>WebFlowTemplate Maven Webapp</name>
    <url>http://maven.apache.org</url>
    <dependencies>

        <dependency>
            <groupId>jstl</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>3.6.3.Final</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>4.3.0.Final</version>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjtools</artifactId>
            <version>1.6.2</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aspects</artifactId>
            <version>3.1.2.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>3.1.2.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.webflow</groupId>
            <artifactId>spring-webflow</artifactId>
            <version>2.3.1.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-core</artifactId>
            <version>3.1.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-web</artifactId>
            <version>3.1.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-config</artifactId>
            <version>3.1.2.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
            <version>3.1.2.RELEASE</version>
        </dependency>


        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>



    </dependencies>
    <build>
        <finalName>WebFlowTemplate</finalName>
    </build>
</project>

看起来一切正常,但我不想看到这个错误。有人可以提供一些信息吗?

【问题讨论】:

  • 你只是缺少 javax.servlet:servlet-api 吗?

标签: java eclipse spring maven spring-security


【解决方案1】:

我也尝试了很多解决方案来解决这个问题。 但是当我查看项目的 maven 依赖项时,我找到了解决方案(我不是指 pom.xml -> 我是指 STS 包资源管理器中的 dropDown-view)。

servlet-api 没有条目。

在我的 pom.xml 中加入以下依赖解决问题:

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
    </dependency>

【讨论】:

    【解决方案2】:

    在你的项目中添加库“Server Runtime”,他就可以正常工作了。

    【讨论】:

      【解决方案3】:

      我发现这个有点奇怪的解决你的问题:

      http://forum.springsource.org/showthread.php?110052-Configuration-problem-spring-security-web-classes-are-not-available-You-need

      最初我以为我在使用 spring security 3.1 时遇到了问题,但是 实际上是因为我使用导入了太多依赖项 行家。

      只导入几个必需的弹簧罐,清洁和重建 项目解决了这个问题,我不再收到我的错误 应用程序上下文 xml 文件

      还可以从 blog 中检查 cmets。

      您正在学习 Spring Security 3.1 教程,对吗?我建议 做一个 mvn clean 清理你的项目的工作区。然后尝试 再次构建项目

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-05-08
        • 2016-10-03
        • 1970-01-01
        • 2018-06-10
        • 1970-01-01
        • 2023-01-24
        • 2020-10-13
        相关资源
        最近更新 更多