我正在尝试将基于Spring Security 2的Web应用程序迁移到Spring 4 / Spring安全3(最新截至2014年6月),我得到了非常奇怪的异常(java.lang.ClassNotFoundException) - 它看起来像某种程度我仍然引用旧的Spring Security 2类,虽然我的自定义类和捆绑的Spring Security 3 jar当然没有它们:

以下是我使用的JAR(Gradle依赖项):

springVersion = '4.0.5.RELEASE'    
springSecurityVersion = '3.2.4.RELEASE'    
jstlVersion ="1.2.1"

compile "org.springframework:spring-core:"+project.springVersion,
        "org.springframework:spring-context:"+project.springVersion,
        "org.springframework:spring-webmvc:"+project.springVersion,
        "org.springframework:spring-web:"+project.springVersion

//Spring security
compile "org.springframework.security:spring-security-core:"+project.springSecurityVersion,
        "org.springframework.security:spring-security-config:"+project.springSecurityVersion,
        "org.springframework.security:spring-security-web:"+project.springSecurityVersion,
        "org.springframework.security:spring-security-acl:"+project.springSecurityVersion,
        "org.springframework.security:spring-security-taglibs:"+project.springSecurityVersion


compile "org.springframework:spring-portlet:2.0.8",
        "org.springframework:spring-struts:3.2.9.RELEASE"

这是我的securityContext.xml配置:

<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-4.0.xsd
                    http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.2.xsd">

<global-method-security secured-annotations="enabled" jsr250-annotations="enabled"/>

<http pattern="/nexuslogin.htm" security="none"/>
<http pattern="/plaksalogin.htm" security="none"/>
<http pattern="/schoolslogin.htm" security="none"/>
<http pattern="/accountverification.htm" security="none"/>    


<http  auto-config="false" entry-point-ref="authenticationProcessingFilterEntryPoint">

    <intercept-url pattern="/dwr/interface/**" access="ROLE_ADMIN_USER,ROLE_CONSUMER,ROLE_EMPLOYER,ROLE_CAREER_SERVICES,ROLE_CARRER_SCHOLARSHIP"/>
    <intercept-url pattern="/admin/**" access="ROLE_ADMIN_USER"/>
    <intercept-url pattern="/employer/**" access="ROLE_EMPLOYER,ROLE_ADMIN_USER"/>
    <intercept-url pattern="/career/scholarshipDashboardPage.htm" access="ROLE_CARRER_SCHOLARSHIP,ROLE_ADMIN_USER"/>
    <intercept-url pattern="/career/**" access="ROLE_CAREER_SERVICES,ROLE_CARRER_SCHOLARSHIP,ROLE_ADMIN_USER"/>

    <intercept-url pattern="/jobs/**" access="ROLE_CONSUMER,ROLE_ADMIN_USER"/>

    <custom-filter position="FORM_LOGIN_FILTER" ref="customeAuthenticationFilter"/>
    <custom-filter after="FILTER_SECURITY_INTERCEPTOR" ref="customeAuthenticationFilter"/>
    <custom-filter position="LAST" ref="accountverificationFilter"/>

</http>

<!-- Determines the login page for the request -->
<beans:bean id="authenticationProcessingFilterEntryPoint" class="com.bodhtree.nexus.view.PlaksaAuthenticationMultiEntryPoint">
    <beans:property name="loginFormUrl" value="nexuslogin.htm" /> 
    <beans:property name="forceHttps" value="false" /> 
</beans:bean> 


<beans:bean id="customeAuthenticationFilter" class="com.bodhtree.nexus.filters.CustomeAuthenticationFilter">
    <beans:property name="authenticationManager" ref="authenticationManager" />
    <beans:property name="filterProcessesUrl" value="/login.htm"/>
    <beans:property name="alwaysUseDefaultTargetUrl" value="false"/>
    <beans:property name="defaultTargetUrl" value="/static/secure.html" />
    <beans:property name="serverSideRedirect" value="false" />
</beans:bean>

<beans:bean id="switchUserProcessingFilter" class="org.springframework.security.web.authentication.switchuser.SwitchUserFilter">
    <beans:property name="userDetailsService" ref="mySQLUserDetailService" />
    <beans:property name="switchUserUrl" value="/admin/j_spring_security_switch_user.htm"/>
    <beans:property name="exitUserUrl"  value="/j_spring_security_exit_user" />
    <beans:property name="targetUrl" value="/jobs/userdashboard.htm" />
</beans:bean>

<beans:bean id="accountverificationFilter" class="com.bodhtree.nexus.filters.AccountVerificationFilter">
    <beans:property name="userDetailsService" ref="mySQLUserDetailService" />    
    <beans:property name="verificationUrl" value="/accverification.htm"/>        
    <beans:property name="failureUrl" value="/accountverification.htm" />
</beans:bean>


<beans:bean id="plaksaAuthenticationProvider" class="com.bodhtree.nexus.security.provider.PlaksaAuthenticationProvider">
    <beans:property name="roles" value="ROLE_ADMIN_USER,ROLE_CONSUMER,ROLE_EMPLOYER,ROLE_CAREER_SERVICES" />
</beans:bean>
<!-- This ensures that remember-me is added as an authentication provider -->
<beans:bean id="rememberMeAuthenticationProvider" class="org.springframework.security.authentication.RememberMeAuthenticationProvider">

    <beans:property name="key" value="boker"/> 
</beans:bean>

<beans:bean id="mySQLUserDetailService" class="com.bodhtree.nexus.model.dao.mysqlimpl.MySQLUserDetailService"/>

<authentication-manager alias="authenticationManager">
    <authentication-provider ref="plaksaAuthenticationProvider" />
    <authentication-provider ref="rememberMeAuthenticationProvider" />
    <authentication-provider user-service-ref="mySQLUserDetailService"/>
</authentication-manager>      
</beans:beans>

以下是例外情况:

22:18:23,549 INFO  [io.undertow.servlet] (MSC service thread 1-3) No Spring WebApplicationInitializer types detected on classpath
22:18:23,557 INFO  [io.undertow.servlet] (MSC service thread 1-3) Initializing Spring root WebApplicationContext
22:18:23,557 INFO  [org.springframework.web.context.ContextLoader] (MSC service thread 1-3) Root WebApplicationContext: initialization started
22:18:23,619 INFO  [org.springframework.web.context.support.XmlWebApplicationContext] (MSC service thread 1-3) Refreshing Root WebApplicationContext: startup date [Sun Jul 06 22:18:23 PDT 2014]; root of context hierarchy
22:18:23,646 INFO  [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] (MSC service thread 1-3) Loading XML bean definitions from class path resource [applicationContext.xml]
22:18:23,667 INFO  [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] (MSC service thread 1-3) Loading XML bean definitions from class path resource [securityContext.xml]
22:18:23,696 INFO  [org.springframework.security.core.SpringSecurityCoreVersion] (MSC service thread 1-3) You are running with Spring Security Core 3.2.4.RELEASE
22:18:23,696 INFO  [org.springframework.security.config.SecurityNamespaceHandler] (MSC service thread 1-3) Spring Security 'config' module version is 3.2.4.RELEASE
22:18:23,753 INFO  [org.springframework.security.config.http.HttpSecurityBeanDefinitionParser] (MSC service thread 1-3) Checking sorted filter chain: [Root bean: class [org.springframework.security.web.context.SecurityContextPersistenceFilter]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null, order = 200, Root bean: class [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null, order = 400, , order = 1100, Root bean: class [org.springframework.security.web.savedrequest.RequestCacheAwareFilter]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null, order = 1600, Root bean: class [org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null, order = 1700, Root bean: class [org.springframework.security.web.authentication.AnonymousAuthenticationFilter]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null, order = 2000, Root bean: class [org.springframework.security.web.session.SessionManagementFilter]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null, order = 2100, Root bean: class [org.springframework.security.web.access.ExceptionTranslationFilter]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null, order = 2200, , order = 2300, , order = 2301, , order = 2147483647]
22:18:23,772 WARN  [org.jboss.modules] (MSC service thread 1-3) Failed to define class com.bodhtree.nexus.view.PlaksaAuthenticationMultiEntryPoint in Module "deployment.smarthires.war:main" from Service Module Loader: java.lang.LinkageError: Failed to link com/bodhtree/nexus/view/PlaksaAuthenticationMultiEntryPoint (Module "deployment.smarthires.war:main" from Service Module Loader)
    at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:487) [jboss-modules.jar:1.3.3.Final]
    at org.jboss.modules.ModuleClassLoader.loadClassLocal(ModuleClassLoader.java:277) [jboss-modules.jar:1.3.3.Final]
    at org.jboss.modules.ModuleClassLoader$1.loadClassLocal(ModuleClassLoader.java:92) [jboss-modules.jar:1.3.3.Final]
    at org.jboss.modules.Module.loadModuleClass(Module.java:568) [jboss-modules.jar:1.3.3.Final]
    at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:205) [jboss-modules.jar:1.3.3.Final]
    at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:459) [jboss-modules.jar:1.3.3.Final]
    at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:408) [jboss-modules.jar:1.3.3.Final]
    at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:389) [jboss-modules.jar:1.3.3.Final]
    at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:134) [jboss-modules.jar:1.3.3.Final]
    at org.springframework.util.ClassUtils.forName(ClassUtils.java:247) [spring-core-4.0.5.RELEASE.jar:4.0.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:395) [spring-beans-4.0.5.RELEASE.jar:4.0.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1348) [spring-beans-4.0.5.RELEASE.jar:4.0.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1319) [spring-beans-4.0.5.RELEASE.jar:4.0.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:594) [spring-beans-4.0.5.RELEASE.jar:4.0.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1396) [spring-beans-4.0.5.RELEASE.jar:4.0.5.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:385) [spring-beans-4.0.5.RELEASE.jar:4.0.5.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:354) [spring-beans-4.0.5.RELEASE.jar:4.0.5.RELEASE]
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:82) [spring-context-4.0.5.RELEASE.jar:4.0.5.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:609) [spring-context-4.0.5.RELEASE.jar:4.0.5.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464) [spring-context-4.0.5.RELEASE.jar:4.0.5.RELEASE]
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403) [spring-web-4.0.5.RELEASE.jar:4.0.5.RELEASE]
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306) [spring-web-4.0.5.RELEASE.jar:4.0.5.RELEASE]
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106) [spring-web-4.0.5.RELEASE.jar:4.0.5.RELEASE]
    at io.undertow.servlet.core.ApplicationListeners.contextInitialized(ApplicationListeners.java:173) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
    at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:190) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
    at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.startContext(UndertowDeploymentService.java:87)
    at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.start(UndertowDeploymentService.java:72)
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948)
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [rt.jar:1.8.0_05]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [rt.jar:1.8.0_05]
    at java.lang.Thread.run(Thread.java:745) [rt.jar:1.8.0_05]
Caused by: java.lang.NoClassDefFoundError: org/springframework/security/ui/webapp/AuthenticationProcessingFilterEntryPoint
    at java.lang.ClassLoader.defineClass1(Native Method) [rt.jar:1.8.0_05]
    at java.lang.ClassLoader.defineClass(ClassLoader.java:760) [rt.jar:1.8.0_05]
    at org.jboss.modules.ModuleClassLoader.doDefineOrLoadClass(ModuleClassLoader.java:361) [jboss-modules.jar:1.3.3.Final]
    at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:482) [jboss-modules.jar:1.3.3.Final]
    ... 31 more
Caused by: java.lang.ClassNotFoundException: org.springframework.security.ui.webapp.AuthenticationProcessingFilterEntryPoint from [Module "deployment.smarthires.war:main" from Service Module Loader]
    at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:213) [jboss-modules.jar:1.3.3.Final]
    at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:459) [jboss-modules.jar:1.3.3.Final]
    at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:408) [jboss-modules.jar:1.3.3.Final]
    at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:389) [jboss-modules.jar:1.3.3.Final]
    at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:134) [jboss-modules.jar:1.3.3.Final]
    ... 35 more