【问题标题】:java.lang.NoClassDefFoundError: org/springframework/security/authentication/AuthenticationManagerjava.lang.NoClassDefFoundError: org/springframework/security/authentication/AuthenticationManager
【发布时间】:2014-09-11 05:54:07
【问题描述】:

我正在尝试通过参考以下链接在 Spring Web 服务上实现身份验证:

http://docs.spring.io/spring-ws/site/reference/html/security.html

以下是我添加的配置:

    <bean
        class="org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping">
        <property name="interceptors">
            <list>
                <ref local="wsServerSecurityInterceptor" />
                <ref local="payloadValidatingIterceptor" />
            </list>
        </property>
    </bean>
    <bean id="wsServerSecurityInterceptor"
        class="org.springframework.ws.soap.security.xwss.XwsSecurityInterceptor">
        <property name="policyConfiguration"
            value="classpath:security/xwss/security-server-policy.xml" />
        <property name="callbackHandlers">
            <list>
                <!-- <ref bean="keyStoreHandlerServer" /> -->
                <ref bean="springSecurityHandler" />
                <ref bean="callbackHandlerServer" />
            </list>
        </property>
    </bean>
    <bean id="springSecurityHandler"
      class="org.springframework.ws.soap.security.xwss.callback.SpringPlainTextPasswordValidationCallbackHandler">
    <property name="authenticationManager" ref="authenticationManager"/>
  </bean>
  <bean id="authenticationManager" class="org.springframework.security.providers.ProviderManager">
      <property name="providers">  
      <list>
    <ref local="authenticationProvider" />
    </list>        
    </property>
  </bean>
  <bean id="authenticationProvider"
   class="org.springframework.security.providers.dao.DaoAuthenticationProvider">
              <property name="userDetailsService" ref="userDetailsService"/>
          </bean>  
   <bean id="userDetailsService" class="com.impl.endpoints.calc.client.JpaUserDetailsService" /> 

在服务器上部署war文件时,出现以下错误:

Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping#0' defined in ServletContext resource [/WEB-INF/xws-spring-ws-servlet.xml]: Cannot resolve reference to bean 'wsServerSecurityInterceptor' while setting bean property 'interceptors' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'wsServerSecurityInterceptor' defined in ServletContext resource [/WEB-INF/xws-spring-ws-servlet.xml]: Cannot resolve reference to bean 'springSecurityHandler' while setting bean property 'callbackHandlers' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityHandler' defined in ServletContext resource [/WEB-INF/xws-spring-ws-servlet.xml]: Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: org/springframework/security/authentication/AuthenticationManager
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:329)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:107)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedList(BeanDefinitionValueResolver.java:353)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:154)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1387)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1128)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)

org/springframework/security/authentication/AuthenticationManager 在配置或代码的任何地方都没有提到。我想知道在哪里需要给定的类以及我需要做哪些配置更改来解决此错误。

编辑:

POM 包含以下 spring 安全 jar:

        <dependency>
        <groupId>
                org.springframework.security
                </groupId>
        <artifactId>spring-security-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-core</artifactId>
        <version>2.0.4</version>
    </dependency>

    <dependency>
        <groupId>
                org.springframework.security
                </groupId>
        <artifactId>spring-security-config</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-taglibs</artifactId>
        <version>3.1.7.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-ldap</artifactId>
        <version>3.1.7.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.ws</groupId>
        <artifactId>spring-ws-security</artifactId>
        <version>2.2.0.RELEASE</version>
        <exclusions>
            <exclusion>
                <groupId>com.sun.xml.wsit</groupId>
                <artifactId>xws-security</artifactId>
            </exclusion>
            <exclusion>
                <groupId>com.sun.xml.wsit</groupId>
                <artifactId>wsit-rt</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

【问题讨论】:

    标签: java spring spring-security spring-ws


    【解决方案1】:

    您在配置中混合使用 Spring Security 2 和 Spring Security 3。对所有 Spring Security jar 使用相同的(和最新的)版本号。 spring-security-core jar 和 3.1.7.RELEASE 其他版本的版本为 2.0.4。为所有 jars 使用当前发布版本,并确保在构建项目时 WEB-INF/lib 中没有不同的版本。

    包名称也在 2 和 3 之间更改。如果您需要知道某个类在哪个包中,请使用 API docs

    【讨论】:

    • 这个答案帮助我注意到“DaoAuthenticationProvider”现在位于不同的包中,“org.springframework.security.authentication.dao”。 Tks
    【解决方案2】:

    下载 org.springframework.security.core.jar 并将其添加到您的类路径中。

    【讨论】:

    • 我的 pom.xml 中已经有了 spring security core jar。我已经添加了应用程序中当前存在的安全 jar 列表。
    • @user3619997 如果jar 在WEB-INF/lib 目录中,你能看看你的war 文件吗?
    • 是的,spring-security-core-2.0.4.jar 存在于 WAR 文件的 WEB-INF/lib 目录中
    • @user3619997 你能验证这个类是否在 jar 中吗?
    • 该类以 org.springframework.security.AuthenticationManager 的形式存在,但在我的代码中,它正在 org.springframework.security.authentication.AuthenticationManager 中搜索它。我试图在这个类中找到该类的 jar链接:findjar.com/… 但找不到。
    猜你喜欢
    • 1970-01-01
    • 2020-08-09
    • 2015-10-14
    • 1970-01-01
    • 2015-08-01
    • 2018-04-15
    • 2013-04-06
    • 2015-04-22
    • 1970-01-01
    相关资源
    最近更新 更多