spring hibernate 整合配置错误

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'managerService' defined in class path resource [com/wondersgroup/pdcl/sunbase1402/manager/managerContext.xml]: Cannot resolve reference to bean 'managerServiceImpl' while setting bean property 'target'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'managerServiceImpl' defined in class path resource [com/wondersgroup/pdcl/sunbase1402/manager/managerContext.xml]: Cannot resolve reference to bean 'managerDAO' while setting bean property 'managerDAO'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'managerDAO' defined in class path resource [com/wondersgroup/pdcl/sunbase1402/manager/managerContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.wondersgroup.framework.core.dao.impl.AbstractHibernateDAOImpl]: Is it an abstract class?; nested exception is java.lang.InstantiationException
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1317)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1076)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:557)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:276)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3843)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4342)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:926)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:889)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1149)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:516)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:578)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'managerServiceImpl' defined in class path resource [com/wondersgroup/pdcl/sunbase1402/manager/managerContext.xml]: Cannot resolve reference to bean 'managerDAO' while setting bean property 'managerDAO'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'managerDAO' defined in class path resource [com/wondersgroup/pdcl/sunbase1402/manager/managerContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.wondersgroup.framework.core.dao.impl.AbstractHibernateDAOImpl]: Is it an abstract class?; nested exception is java.lang.InstantiationException
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1317)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1076)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:322)
... 39 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'managerDAO' defined in class path resource [com/wondersgroup/pdcl/sunbase1402/manager/managerContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.wondersgroup.framework.core.dao.impl.AbstractHibernateDAOImpl]: Is it an abstract class?; nested exception is java.lang.InstantiationException
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:955)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:901)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:322)
... 49 more
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.wondersgroup.framework.core.dao.impl.AbstractHibernateDAOImpl]: Is it an abstract class?; nested exception is java.lang.InstantiationException
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:129)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:71)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:948)
... 57 more
Caused by: java.lang.InstantiationException
at sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(InstantiationExceptionConstructorAccessorImpl.java:30)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:126)
... 59 more

2个回答

abstractDAO这个bean的配置呢?AbstractHibernateDAOImpl这个类的代码呢?

zyn010101
zyn010101 百度一下 spring bean 抽象 继承,尝试一下他们的方案
6 年多之前 回复
wm3445
wm3445 我自己研究 下吧
6 年多之前 回复
zyn010101
zyn010101 参考下这个:http://blog.csdn.net/shendeguang/article/details/8188732
6 年多之前 回复
wm3445
wm3445 无法实例化bean啊
6 年多之前 回复
wm3445
wm3445 还是那个错误啊 Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'managerServiceImpl' defined in class path resource [com/wondersgroup/pdcl/sunbase1402/manager/managerContext.xml]: Cannot resolve reference to bean 'managerDAO' while setting bean property 'managerDAO'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'managerDAO' defined in class path resource [com/wondersgroup/pdcl/sunbase1402/manager/managerContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.wondersgroup.framework.core.dao.impl.AbstractHibernateDAOImpl]: Is it an abstract class?; nested exception is java.lang.InstantiationException
6 年多之前 回复
zyn010101
zyn010101 把sessionFactory注入到managerDAO后报什么错误?
6 年多之前 回复
wm3445
wm3445 看了下 还是会出错啊
6 年多之前 回复
wm3445
wm3445 我看下啊。
6 年多之前 回复
zyn010101
zyn010101 <bean id="managerDAO" parent="abstractDAO" > <property name="target" ref="managerDAOImpl"/> <property name="sessionFactory" ref="sessionFactory" /> </bean> 试试这个,参考:http://hi.baidu.com/sdhzlzhk/item/ebc9fa488fb9e8a9de2a9f71
6 年多之前 回复
wm3445
wm3445 这个类的配置 <bean id="abstractDAO" abstract="true" class="com.wondersgroup.framework.core.dao.impl.AbstractHibernateDAOImpl"> <property name="sessionFactory" ref="sessionFactory" /> </bean> 这个类代码 没看 框架封装起来的
6 年多之前 回复

看错误是因为你的AbstractHibernateDAOImpl是一个抽象类,而spring要去调用BeanUtils.instantiate(Class<?>)去初始化该抽象类,显然是会有问题的。可以尝试配置下这个bean AbstractHibernateDAOImpl,并将其abstract=“true”,然后
[code="java"]

[/code]使parent指向你的AbstractHibernateDAOImpl对应的bean id。

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问