我正在获取BeanCreationException创建派生类的bean

时间:2015-05-25 07:33:43

标签: java spring java-ee

我正在尝试实施factory设计模式。

我创建了一个interface IAuthenticationHandler

public interface IAuthenticationHandler {

    public boolean validate(User user);
}

并在AuthenticationHandler

中实现
public class AuthenticationHandler extends IAuthenticationHandler{

    private UserDao userDao;

    @Override
    public boolean validate(User user){
         // validate logic
    }

}

我使用Spring创建AuthenticationHandler的bean

 authenticationHandler = (AuthenticationHandler) StaticContextHolder
                .getBean("authenticationHandler");

但是我得到了BeanCreationException。我添加了stacktrace。

2015-05-25/11:19:56.432/IST [localhost-startStop-1] [ERROR] org.springframework.web.context.ContextLoader:318 - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'shiroFilter' defined in URL [file:/C:/Program%20Files/Apache/apache-tomcat-7.0.57/webapps/test/WEB-INF/classes/applicationContext.xml]: Cannot resolve reference to bean 'securityManager' while setting bean property 'securityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'securityManager' defined in URL [file:/C:/Program%20Files/Apache/apache-tomcat-7.0.57/webapps/test/WEB-INF/classes/applicationContext.xml]: Cannot resolve reference to bean 'jdbcRealm' while setting bean property 'realms' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jdbcRealm' defined in URL [file:/C:/Program%20Files/Apache/apache-tomcat-7.0.57/webapps/test/WEB-INF/classes/applicationContext.xml]: Cannot resolve reference to bean 'authenticationHandler' while setting bean property 'authenticationHandler'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'authenticationHandler' defined in URL [file:/C:/Program%20Files/Apache/apache-tomcat-7.0.57/webapps/test/WEB-INF/classes/applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'com.sun.proxy.$Proxy29 implementing com.test.handler.IAuthenticationHandler,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised' to required type 'com.test.handler.AuthenticationHandler' for property 'authenticationHandler'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [com.sun.proxy.$Proxy29 implementing com.test.handler.IAuthenticationHandler,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [com.test.handler.AuthenticationHandler] for property 'authenticationHandler': no matching editors or conversion strategy found
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:107)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1456)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1197)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.registerBeanPostProcessors(PostProcessorRegistrationDelegate.java:232)
    at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:618)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:467)
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:381)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:293)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4994)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5492)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:649)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1081)
    at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1877)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    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 'securityManager' defined in URL [file:/C:/Program%20Files/Apache/apache-tomcat-7.0.57/webapps/test/WEB-INF/classes/applicationContext.xml]: Cannot resolve reference to bean 'jdbcRealm' while setting bean property 'realms' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jdbcRealm' defined in URL [file:/C:/Program%20Files/Apache/apache-tomcat-7.0.57/webapps/test/WEB-INF/classes/applicationContext.xml]: Cannot resolve reference to bean 'authenticationHandler' while setting bean property 'authenticationHandler'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'authenticationHandler' defined in URL [file:/C:/Program%20Files/Apache/apache-tomcat-7.0.57/webapps/test/WEB-INF/classes/applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'com.sun.proxy.$Proxy29 implementing com.test.handler.IAuthenticationHandler,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised' to required type 'com.test.handler.AuthenticationHandler' for property 'authenticationHandler'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [com.sun.proxy.$Proxy29 implementing com.test.handler.IAuthenticationHandler,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [com.test.handler.AuthenticationHandler] for property 'authenticationHandler': no matching editors or conversion strategy found
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:107)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedList(BeanDefinitionValueResolver.java:351)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:154)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1456)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1197)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:320)
    ... 28 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jdbcRealm' defined in URL [file:/C:/Program%20Files/Apache/apache-tomcat-7.0.57/webapps/test/WEB-INF/classes/applicationContext.xml]: Cannot resolve reference to bean 'authenticationHandler' while setting bean property 'authenticationHandler'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'authenticationHandler' defined in URL [file:/C:/Program%20Files/Apache/apache-tomcat-7.0.57/webapps/test/WEB-INF/classes/applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'com.sun.proxy.$Proxy29 implementing com.test.handler.IAuthenticationHandler,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised' to required type 'com.test.handler.AuthenticationHandler' for property 'authenticationHandler'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [com.sun.proxy.$Proxy29 implementing com.test.handler.IAuthenticationHandler,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [com.test.handler.AuthenticationHandler] for property 'authenticationHandler': no matching editors or conversion strategy found
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:107)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1456)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1197)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:320)
    ... 40 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'authenticationHandler' defined in URL [file:/C:/Program%20Files/Apache/apache-tomcat-7.0.57/webapps/test/WEB-INF/classes/applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'com.sun.proxy.$Proxy29 implementing com.test.handler.IAuthenticationHandler,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised' to required type 'com.test.handler.AuthenticationHandler' for property 'authenticationHandler'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [com.sun.proxy.$Proxy29 implementing com.test.handler.IAuthenticationHandler,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [com.test.handler.AuthenticationHandler] for property 'authenticationHandler': no matching editors or conversion strategy found
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:547)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:320)
    ... 50 more
Caused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'com.sun.proxy.$Proxy29 implementing com.test.handler.IAuthenticationHandler,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised' to required type 'com.test.handler.AuthenticationHandler' for property 'authenticationHandler'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [com.sun.proxy.$Proxy29 implementing com.test.handler.IAuthenticationHandler,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [com.test.handler.AuthenticationHandler] for property 'authenticationHandler': no matching editors or conversion strategy found
    at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:473)
    at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:509)
    at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:504)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1502)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1461)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1197)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
    ... 56 more
Caused by: java.lang.IllegalStateException: Cannot convert value of type [com.sun.proxy.$Proxy29 implementing com.test.handler.IAuthenticationHandler,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [com.test.handler.AuthenticationHandler] for property 'authenticationHandler': no matching editors or conversion strategy found
    at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:267)
    at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:458)
    ... 62 more

0 个答案:

没有答案