java.lang.NoClassDefFoundError: org/springframework/security/authentication/AuthenticationManager
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25780026/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
java.lang.NoClassDefFoundError: org/springframework/security/authentication/AuthenticationManager
提问by user3619997
I am trying to implement authentication on Spring web service by referring the following link:
我正在尝试通过参考以下链接在 Spring Web 服务上实现身份验证:
http://docs.spring.io/spring-ws/site/reference/html/security.html
http://docs.spring.io/spring-ws/site/reference/html/security.html
Following is the configuration I have added:
以下是我添加的配置:
<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" />
While deploying the war file on server, I get following error:
在服务器上部署 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.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
org/springframework/security/authentication/AuthenticationManager is not mentioned anywhere in the configuration or the code. I wonder where exactly the given class is required and what configuration change I need to do to resolve this error.
org/springframework/security/authentication/AuthenticationManager 未在配置或代码中的任何地方提及。我想知道到底在哪里需要给定的类以及我需要做哪些配置更改来解决此错误。
EDIT:
编辑:
POM contains following spring security jars:
POM 包含以下弹簧安全罐:
<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>
采纳答案by Shaun the Sheep
You are mixing Spring Security 2 and Spring Security 3 in your configuration. Use the same (and the latest) version number for all the Spring Security jars. You have version 2.0.4 for the spring-security-core
jar and 3.1.7.RELEASE
for other ones. Use the current release version for all the jars, and make sure there aren't different versions in your WEB-INF/lib
when you've built the project.
您正在配置中混合使用 Spring Security 2 和 Spring Security 3。对所有 Spring Security jar 使用相同(和最新)的版本号。您有 2.0.4 版本的spring-security-core
jar 和3.1.7.RELEASE
其他版本。对所有 jar 使用当前发布版本,并确保WEB-INF/lib
在构建项目时没有不同的版本。
The package names also changed between 2 and 3. Use the API docsif you need to know what package a class is in.
包名称也在 2 和 3 之间更改。如果您需要知道类在哪个包中,请使用API 文档。
回答by Jens
Download org.springframework.security.core.jar
and add it ro your classpath.
下载org.springframework.security.core.jar
并将其添加到您的类路径中。