我在我的应用程序中添加了3个bean' XML文件
<bean id="rememberMeServices"
class="org.springframework.security.web.authentication.rememberme.TokenBasedRememberMeServices">
<property name="userDetailsService" ref="myUserDetailsService" />
<property name="key" value="springRocks" />
</bean>
<bean id="rememberMeAuthenticationProvider"
class="org.springframework.security.authentication.rememberme.RememberMeAuthenticationProvider">
<property name="key" value="springRocks" />
</bean>
此外,我还将spring-security-web,spring-security-core,spring-security-config,spring-context依赖项添加到POM文件中。
但是,我仍然收到以下错误消息: org.springframework.beans.factory.BeanCreationException:创建名称为&#39; rememberMeFilter&#39;在类路径资源[META-INF / App-setup / applicationcontext-security.xml]中定义:bean的实例化失败;嵌套异常是org.springframework.beans.BeanInstantiationException:无法实例化[org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter]:找不到默认构造函数;嵌套异常是java.lang.NoSuchMethodException:org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter。() 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1101) 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1046) 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504) 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) at org.springframework.beans.factory.support.AbstractBeanFactory $ 1.getObject(AbstractBeanFactory.java:303) 在org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) 在org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) 在org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755) 在org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757) 在org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480) at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403) 在org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306) 在org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106) at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:800) at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:444) at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:791) at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:294) 在org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1349) 在org.eclipse.jetty.maven.plugin.JettyWebAppContext.startWebapp(JettyWebAppContext.java:296) at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1342) at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:741) 在org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:505) 在org.eclipse.jetty.maven.plugin.JettyWebAppContext.doStart(JettyWebAppContext.java:365) at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) 在org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:132) 在org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:114) at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:61) 在org.eclipse.jetty.server.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:163) at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) 在org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:132) 在org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:114) at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:61) at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) 在org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:132) 在org.eclipse.jetty.server.Server.start(Server.java:387) 在org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:114) at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:61) 在org.eclipse.jetty.server.Server.doStart(Server.java:354) 在org.eclipse.jetty.maven.plugin.JettyServer.doStart(JettyServer.java:73) at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) 在org.eclipse.jetty.maven.plugin.AbstractJettyMojo.startJetty(AbstractJettyMojo.java:534) 在org.eclipse.jetty.maven.plugin.AbstractJettyMojo.execute(AbstractJettyMojo.java:357) 在org.eclipse.jetty.maven.plugin.JettyRunMojo.execute(JettyRunMojo.java:167) 在org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134) 在org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208) 在org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153) 在org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145) 在org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116) 在org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80) 在org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51) 在org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128) 在org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307) 在org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193) 在org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106) 在org.apache.maven.cli.MavenCli.execute(MavenCli.java:862) 在org.apache.maven.cli.MavenCli.doMain(MavenCli.java:286) 在org.apache.maven.cli.MavenCli.main(MavenCli.java:197) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) 在org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289) 在org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229) 在org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415) 在org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356) 引起:org.springframework.beans.BeanInstantiationException:无法实例化[org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter]:找不到默认构造函数;嵌套异常是java.lang.NoSuchMethodException:org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter。() 在org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:85) 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1094) ......还有65个 引起:java.lang.NoSuchMethodException:org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter。() 在java.lang.Class.getConstructor0(Class.java:3082) at java.lang.Class.getDeclaredConstructor(Class.java:2178) 在org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:80) ... 66更多
我错过了任何依赖吗?
答案 0 :(得分:0)
RememberMeAuthenticatioinProvider的正确类路径是:
org.springframework.security.authentication.RememberMeAuthenticationProvider
我认为您的文档中存在拼写错误。
您的其他bean引用也应该更新
修改强>
您似乎正在使用比您的文档更新版本的RememberMeAuthenticationProvider
。
RememberMeAuthenticationProvider
的默认构造函数不再公开。这是唯一剩下的构造函数:
RememberMeAuthenticationFilter(AuthenticationManager authenticationManager, RememberMeServices rememberMeServices)
所以你必须提供构造函数参数:
<bean id="rememberMeAuthenticationProvider"
class="org.springframework.security.authentication.rememberme.RememberMeAuthenticationProvider">
<constructor-arg ref="yourAuthManager"/>
<constructor-arg ref="rememberMeServices"/>
<property name="key" value="springRocks" />
</bean>