Spring-Security :java.lang.NoClassDefFoundError: org/springframework/security/context/DelegatingApplicationListener
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31591928/
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
Spring- Security :java.lang.NoClassDefFoundError: org/springframework/security/context/DelegatingApplicationListener
提问by We are Borg
I am upgrading the Spring-Security version from 3.2.5 to 4.0.1. Unfortunately I have stumbled across a road-block and I would appreciate your help. I am posting the error log, the securityApplicationContext.xml and pom.xml. Kindly have a look.
我正在将 Spring-Security 版本从 3.2.5 升级到 4.0.1。不幸的是,我遇到了一个障碍,非常感谢您的帮助。我正在发布错误日志、securityApplicationContext.xml 和 pom.xml。请看一下。
Error log :
错误日志:
javax.servlet.ServletException: java.lang.NoSuchMethodError: org.springframework.security.web.access.expression.WebSecurityExpressionRoot.setDefaultRolePrefix(Ljava/lang/String;)V
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:916)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:845)
org.apache.jsp.WEB_002dINF.views.common.footer_jsp._jspService(footer_jsp.java:231)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
SecurityApplicationContext.xml :
SecurityApplicationContext.xml :
<security:http pattern="/resources/**" security="none"/>
<security:http create-session="ifRequired" use-expressions="true" auto-config="false" disable-url-rewriting="true">
<security:form-login login-page="/login" login-processing-url="/j_spring_security_check" default-target-url="/dashboard" always-use-default-target="false" authentication-failure-url="/denied" />
<security:remember-me key="_spring_security_remember_me" user-service-ref="userDetailsService" token-validity-seconds="1209600" data-source-ref="dataSource"/>
<security:logout delete-cookies="JSESSIONID" invalidate-session="true" logout-url="/j_spring_security_logout"/>
<!-- <security:intercept-url pattern="/**" requires-channel="https"/> -->
<security:port-mappings>
<security:port-mapping http="8080" https="8443"/>
</security:port-mappings>
<security:logout logout-url="/logout" logout-success-url="/" success-handler-ref="myLogoutHandler"/>
<security:session-management session-fixation-protection="migrateSession">
<security:concurrency-control session-registry-ref="sessionRegistry" max-sessions="5" expired-url="/login"/>
</security:session-management>
</security:http>
<beans:bean id="rememberMeAuthenticationProvider" class="org.springframework.security.web.authentication.rememberme.PersistentTokenBasedRememberMeServices">
<beans:constructor-arg index="0" value="_spring_security_remember_me"/>
<beans:constructor-arg index="1" ref="userDetailsService"/>
<beans:constructor-arg index="2" ref="jdbcTokenRepository"/>
<property name="alwaysRemember" value="true"/>
</beans:bean>
<!--Database management for remember-me -->
<beans:bean id="jdbcTokenRepository"
class="org.springframework.security.web.authentication.rememberme.JdbcTokenRepositoryImpl">
<beans:property name="createTableOnStartup" value="false"/>
<beans:property name="dataSource" ref="dataSource" />
</beans:bean>
<!-- Remember me ends here -->
<security:authentication-manager alias="authenticationManager">
<security:authentication-provider user-service-ref="LoginServiceImpl">
<security:password-encoder ref="encoder"/>
</security:authentication-provider>
</security:authentication-manager>
<beans:bean id="encoder"
class="org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder">
<beans:constructor-arg name="strength" value="11" />
</beans:bean>
<beans:bean id="daoAuthenticationProvider"
class="org.springframework.security.authentication.dao.DaoAuthenticationProvider">
<beans:property name="userDetailsService" ref="LoginServiceImpl"/>
<beans:property name="passwordEncoder" ref="encoder"/>
</beans:bean>
</beans>
And POM.xml :
和 POM.xml :
<packaging>war</packaging>
<properties>
<java-version>1.8</java-version>
<org.springframework-version>4.0.6.RELEASE</org.springframework-version>
<org.aspectj-version>1.7.4</org.aspectj-version>
<org.slf4j-version>1.7.5</org.slf4j-version>
<hibernate.version>4.3.9.Final</hibernate.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<springsecurity.version>4.0.1.RELEASE</springsecurity.version>
</properties>
<dependencies>
<!-- Spring Mobile dependencies -->
<dependency>
<groupId>org.springframework.mobile</groupId>
<artifactId>spring-mobile-device</artifactId>
<version>1.1.3.RELEASE</version>
</dependency>
<!-- Spring mobile ends here -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</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-webmvc</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-core</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<!-- Spring security dependenciey -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>${springsecurity.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>${springsecurity.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-taglibs</artifactId>
<version>${springsecurity.version}</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
If there is anything more required, kindly let me know. Thanks a lot. :-)
如果还有什么需要,请告诉我。非常感谢。:-)
回答by smoggers
Firstly, you also need the spring-security-core
dependency within your pom.xml.
首先,您还需要spring-security-core
pom.xml 中的依赖项。
Secondly, the error message you are receiving is to do with incompatible versions between Spring and Spring-Security. I thought using
其次,您收到的错误消息与 Spring 和 Spring-Security 之间的版本不兼容有关。我想用
<org.springframework-version>4.0.6.RELEASE</org.springframework-version>
with <springsecurity.version>4.0.1.RELEASE</springsecurity.version>
as you currently have would work fine but then I noticed this line in the Spring-Security documentationregarding migration to Spring-Security 4:
<org.springframework-version>4.0.6.RELEASE</org.springframework-version>
与<springsecurity.version>4.0.1.RELEASE</springsecurity.version>
您目前拥有的一样可以正常工作,但后来我注意到Spring-Security 文档中关于迁移到 Spring-Security 4 的这一行:
"Spring Security 4 now requires Spring 4. This means your first step is to update to Spring 4.1.x."
“Spring Security 4 现在需要 Spring 4。这意味着您的第一步是更新到 Spring 4.1.x。”
My configuration also uses Spring version 4.1.1.RELEASE and works well with Spring-Security.
我的配置也使用 Spring 版本 4.1.1.RELEASE 并且与 Spring-Security 配合良好。
Therefore I'd say your best bet is to upgrade your <org.springframework-version>
to version 4.1 or above.
因此,我认为最好的办法是将您<org.springframework-version>
的版本升级到4.1 或更高版本。
回答by prisar
Adding these security packages will solve the issue. more importantly, spring core should be there.
添加这些安全包将解决问题。更重要的是,弹簧芯应该在那里。
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>5.2.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>5.2.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>5.2.1.RELEASE</version>
</dependency>