Spring- Security :java.lang.NoClassDefFoundError: org/springframework/security/context/DelegatingApplicationListener
Solution 1
Firstly, you also need the spring-security-core
dependency within your pom.xml.
Secondly, the error message you are receiving is to do with incompatible versions between Spring and Spring-Security. I thought using
<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 documentation regarding migration to Spring-Security 4:
"Spring Security 4 now requires Spring 4. This means your first step is to update to Spring 4.1.x."
My configuration also uses Spring version 4.1.1.RELEASE and works well with Spring-Security.
Therefore I'd say your best bet is to upgrade your <org.springframework-version>
to version 4.1 or above.
Solution 2
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>
We are Borg
Working in Pune,India. Open to meet new people, attend conferences, good talks. For followup on any answer or any doubt about posts on SO, email at kernelfreak[at]gmail.com :-)
Updated on December 16, 2020Comments
-
We are Borg over 3 years
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.
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 :
<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 :
<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. :-)