Can't resolve reference to bean 'dataSource' in parent factory: no parent factory available

1、错误描述

[plain]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. 2016-03-05 11:19:53 WARN [org.springframework.web.context.support.XmlWebApplicationContext] Exception encountered during context initialization - cancelling refresh attempt  
  2. org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Can't resolve reference to bean 'dataSource' in parent factory: no parent factory available  
  3.     at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:336)  
  4.     at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)  
  5.     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1471)  
  6.     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1216)  
  7.     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:538)  
  8.     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)  
  9.     at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)  
  10.     at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:229)  
  11.     at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)  
  12.     at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)  
  13.     at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:706)  
  14.     at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)  
  15.     at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)  
  16.     at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)  
  17.     at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)  
  18.     at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)  
  19.     at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5068)  
  20.     at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5584)  
  21.     at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)  
  22.     at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1572)  
  23.     at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1562)  
  24.     at java.util.concurrent.FutureTask.run(FutureTask.java:262)  
  25.     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)  
  26.     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)  
  27.     at java.lang.Thread.run(Thread.java:745)  
  28. Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Can't resolve reference to bean 'dataSource' in parent factory: no parent factory available  
  29.     at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:321)  
  30.     ... 24 more  
  31. 2016-03-05 11:19:53 ERROR [org.springframework.web.context.ContextLoader] Context initialization failed  
  32. org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Can't resolve reference to bean 'dataSource' in parent factory: no parent factory available  
  33.     at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:336)  
  34.     at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)  
  35.     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1471)  
  36.     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1216)  
  37.     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:538)  
  38.     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)  
  39.     at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)  
  40.     at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:229)  
  41.     at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)  
  42.     at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)  
  43.     at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:706)  
  44.     at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)  
  45.     at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)  
  46.     at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)  
  47.     at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)  
  48.     at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)  
  49.     at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5068)  
  50.     at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5584)  
  51.     at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)  
  52.     at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1572)  
  53.     at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1562)  
  54.     at java.util.concurrent.FutureTask.run(FutureTask.java:262)  
  55.     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)  
  56.     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)  
  57.     at java.lang.Thread.run(Thread.java:745)  
  58. Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Can't resolve reference to bean 'dataSource' in parent factory: no parent factory available  
  59.     at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:321)  
  60.     ... 24 more  
  61. 三月 05, 2016 11:19:53 上午 org.apache.catalina.core.StandardContext listenerStart  
  62. 严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener  
  63. org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Can't resolve reference to bean 'dataSource' in parent factory: no parent factory available  
  64.     at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:336)  
  65.     at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)  
  66.     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1471)  
  67.     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1216)  
  68.     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:538)  
  69.     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)  
  70.     at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)  
  71.     at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:229)  
  72.     at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)  
  73.     at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)  
  74.     at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:706)  
  75.     at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)  
  76.     at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)  
  77.     at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)  
  78.     at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)  
  79.     at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)  
  80.     at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5068)  
  81.     at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5584)  
  82.     at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)  
  83.     at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1572)  
  84.     at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1562)  
  85.     at java.util.concurrent.FutureTask.run(FutureTask.java:262)  
  86.     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)  
  87.     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)  
  88.     at java.lang.Thread.run(Thread.java:745)  
  89. Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Can't resolve reference to bean 'dataSource' in parent factory: no parent factory available  
  90.     at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:321)  
  91.     ... 24 more  

2、错误原因

[plain]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. <bean id="sessionFactory"    
  2.        class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">    
  3.        <property name="dataSource">    
  4.                <ref  parent="dataSource"/>  
  5.        </property>    
  6. </bean>  
     <ref/>中用了parent属性,正确的配置是<ref bean="dataSource"/>

3、解决办法

[plain]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. <bean id="sessionFactory"    
  2.        class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">    
  3.        <property name="dataSource">    
  4.                <ref  bean="dataSource"/>  
  5.        </property>    
  6. </bean>  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

李晓LOVE向阳

你的鼓励是我持续的不断动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值