ClassNotFoundException DelegatingFilterProxy

Posted

技术标签:

【中文标题】ClassNotFoundException DelegatingFilterProxy【英文标题】: 【发布时间】:2012-10-05 15:25:00 【问题描述】:

我正在尝试使用 Spring 安全性执行一些自定义身份验证。

我已经阅读了一些关于它的内容:

https://***.com/a/4074532/759452 https://***.com/a/2701722/759452 http://static.springsource.org/spring-security/site/

我还发现了一个关于这个 的有趣对话:http://forum.springsource.org/showthread.php?53972-Problem-when-finding-springSecurityFilterChain-bean

所以,在我的 web.xml 中有

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
  <display-name>Secured Account</display-name>

  <servlet>
    <servlet-name>mysecuredapp</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>mysecuredapp</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>


  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/mysecuredapp-security.xml</param-value>
  </context-param>


  <filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

</web-app>

在 mysecuredapp-servlet.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.0.xsd 
        http://www.springframework.org/schema/security
        http://www.springframework.org/schema/security/spring-security-3.0.xsd" >

    <http auto-config="true">
        <intercept-url pattern="/account/*" access="ROLE_USER, ROLE_ADMIN, ROLE_MASTER" />
        <intercept-url pattern="/admin/*" access="ROLE_ADMIN, ROLE_MASTER" />
        <intercept-url pattern="/master/*" access="ROLE_MASTER" />
    </http>


    <authentication-manager>
        <authentication-provider ref="daoAuthenticationProvider" />
    </authentication-manager>

    <beans:bean id="daoAuthenticationProvider" class="org.springframework.security.authentication.dao.DaoAuthenticationProvider" >
        <beans:property name="userDetailsService" ref="userDetailsService" />
    </beans:bean>


</beans:beans>

这是我的 pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>

  <groupId>MySecuredApp</groupId>
  <artifactId>securedApp</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>war</packaging>

  <name>My Secured App - Spring Hibernate Maven</name>
  <properties>
        <org.springframework.version>3.0.5.RELEASE</org.springframework.version>
        <javax.servlet.jstl.version>1.2</javax.servlet.jstl.version>
        <org.hibernate>3.6.10.Final</org.hibernate>
        <org.springsecurity.version>3.1.2.RELEASE</org.springsecurity.version>
    </properties>

  <dependencies>
        <!-- Hibernate deps -->
        <dependency>
            <groupId>org.hibernate.javax.persistence</groupId>
            <artifactId>hibernate-jpa-2.0-api</artifactId>
            <version>1.0.1.Final</version>
        </dependency>
        <dependency>
          <groupId>org.hibernate</groupId>
          <artifactId>hibernate-entitymanager</artifactId>
          <version>$org.hibernate</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>$org.hibernate</version>
        </dependency>

        <!-- Spring security deps -->
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-core</artifactId>
            <version>$org.springsecurity.version</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-web</artifactId>
            <version>$org.springsecurity.version</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-config</artifactId>
            <version>$org.springsecurity.version</version>
        </dependency>
        <!-- Spring deps -->
        <dependency>
             <groupId>org.springframework</groupId>
             <artifactId>spring-context</artifactId>
             <version>$org.springframework.version</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>$org.springframework.version</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>$org.springframework.version</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>$org.springframework.version</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>$org.springframework.version</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>$org.springframework.version</version>
            <scope>test</scope>
        </dependency>

        <!-- Misc deps -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>$javax.servlet.jstl.version</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.10</version>
        </dependency>
        <dependency>
            <groupId>commons-dbcp</groupId>
            <artifactId>commons-dbcp</artifactId>
            <version>1.4</version>
        </dependency>
        <dependency>
            <groupId>commons-pool</groupId>
            <artifactId>commons-pool</artifactId>
            <version>20030825.183949</version>
        </dependency>
        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
            <version>1.2.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-io</artifactId>
            <version>1.3.2</version>
        </dependency>

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

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

  </dependencies>

  <build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
                <encoding>UTF8</encoding>
            </configuration>
            <inherited>true</inherited>
        </plugin>
    </plugins>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>
    <testResources>
        <testResource>
            <directory>src/test/resources</directory>
            <filtering>true</filtering>
        </testResource>
        <testResource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </testResource>
    </testResources>
  </build>
</project>

当我启动 tomcat(在 Eclipse 中)时,我得到了这个 。知道为什么会出现这种情况吗?

提前致谢

【问题讨论】:

【参考方案1】:

这是我自己犯的一个愚蠢的错误......因为我遇到问题的原因完全相同:不包括部署程序集的 Spring 依赖项。

有关详细信息,请参阅我之前发布的此答案:Maven + Spring + Dynamic Web Module ( Eclipse ) = java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener

【讨论】:

你能相信我有同样的问题(和同样的修复)吗?我无法解释为什么会发生这种情况......【参考方案2】:

过滤器链是否有可能没有选择您的用户详细信息服务 bean?您的 mysecuredapp-servlet.xml 文件中似乎没有组件扫描指令,并且委派过滤器的 contextConfigLocation 仅指向该文件。

我可能是错的,但我相当确定过滤器的 Spring 上下文与调度程序 servlet 的上下文是分开的。您需要在安全 XML 文件中包含组件扫描,或者将主 Spring beans 文件添加到 contextConfigLocation。

【讨论】:

我用 更新了 mysecuredapp-security.xml 但我仍然遇到同样的错误。

以上是关于ClassNotFoundException DelegatingFilterProxy的主要内容,如果未能解决你的问题,请参考以下文章

java.lang.ClassNotFoundException 运行 jar 文件时 Spring Boot 中的 java.lang.ClassNotFoundException - 添加库

ClassNotFoundException:org.sqlite.JDBC

ClassNotFoundException和NoClassDefFoundError

ClassNotFoundException和NoClassDefFoundError

ClassNotFoundException:oracle.jdbc.driver.OracleDriver

如何解决 ClassNotFoundException?