2016-09-23 115 views
0

我是将Spring和Spring安全性从3.0.3更新到Spring 4.2.4和Spring security 4.0.3的过程。我得到这个错误创建bean与..并没有找到ExceptionTranslationFilter类的默认构造函数。这个类有两个重载的构造函数,但没有定义默认的构造函数。有没有办法解决这个异常?从Spring 3.x迁移到4.x(没有找到默认构造函数)

堆栈跟踪:

SEVERE: Exception sending context initialized event to listener instance of class com.mercuryinsurance.esignature.ui.webapp.listener.StartupListener 
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityFilterChain' defined in ServletContext resource [/WEB-INF/conf/context-ui-security.xml]: Cannot create inner bean '(inner bean)#676359c2' of type [org.springframework.security.web.DefaultSecurityFilterChain] while setting constructor argument with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#676359c2': Cannot resolve reference to bean 'exceptionTranslationFilter' while setting constructor argument with key [2]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'exceptionTranslationFilter' defined in ServletContext resource [/WEB-INF/conf/context-ui-security.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.security.web.access.ExceptionTranslationFilter]: No default constructor found; nested exception is java.lang.NoSuchMethodException: org.springframework.security.web.access.ExceptionTranslationFilter.<init>() 
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:313) 
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:129) 
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedList(BeanDefinitionValueResolver.java:382) 
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:157) 
at org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:648) 
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:140) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1143) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1046) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) 
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) 
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) 
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) 
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) 
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772) 
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839) 
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538) 
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:446) 
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:328) 
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107) 
at com.mercuryinsurance.esignature.ui.webapp.listener.StartupListener.contextInitialized(StartupListener.java:15) 
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4939) 
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434) 
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) 
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559) 
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549) 
at java.util.concurrent.FutureTask.run(FutureTask.java:262) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) 
at java.lang.Thread.run(Thread.java:745) 
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#676359c2': Cannot resolve reference to bean 'exceptionTranslationFilter' while setting constructor argument with key [2]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'exceptionTranslationFilter' defined in ServletContext resource [/WEB-INF/conf/context-ui-security.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.security.web.access.ExceptionTranslationFilter]: No default constructor found; nested exception is java.lang.NoSuchMethodException: org.springframework.security.web.access.ExceptionTranslationFilter.<init>() 
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359) 
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108) 
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedList(BeanDefinitionValueResolver.java:382) 
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:157) 
at org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:634) 
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:140) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1143) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1046) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) 
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:299) 
... 29 more 
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'exceptionTranslationFilter' defined in ServletContext resource [/WEB-INF/conf/context-ui-security.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.security.web.access.ExceptionTranslationFilter]: No default constructor found; nested exception is java.lang.NoSuchMethodException: org.springframework.security.web.access.ExceptionTranslationFilter.<init>() 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1105) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1050) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) 
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) 
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) 
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) 
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) 
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351) 
... 39 more 
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.security.web.access.ExceptionTranslationFilter]: No default constructor found; nested exception is java.lang.NoSuchMethodException: org.springframework.security.web.access.ExceptionTranslationFilter.<init>() 
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:85) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1098) 
... 47 more 
Caused by: java.lang.NoSuchMethodException: org.springframework.security.web.access.ExceptionTranslationFilter.<init>() 
at java.lang.Class.getConstructor0(Class.java:2892) 
at java.lang.Class.getDeclaredConstructor(Class.java:2058) 
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:80) 
... 48 more 
+5

的'NoSuchMethodException指定的默认构造函数'建议你使用的库不兼容(例如,某些引用3.x的东西,某些引用4.x的东西)。检查你的依赖关系,确保它们匹配。另外[本指南](http://docs.spring.io/spring-security/site/migrate/current/3-to-4/html5/migrate-3-to-4-jc.html)可能对您。 – nbrooks

+0

感谢您的指导。 – Jaykumar

回答

0

我想通了。 我不能发表一个简单直接的答案,因为我必须更改配置文件中连接的很多bean。在Spring 4.x中,我发现大多数setter注入被替换为构造注入。

因此,对于每次获取错误的bean,无论是创建bean还是默认构造函数都没有找到,我必须通过文档了解该属性是否可以通过setter访问,或者如果它们是在构造函数中传递的,我不得不修改我的配置文件。这并不好玩,但我经历了。从3.X到4.x的

春季迁徙是超级有用