问题描述
服务器是tomcat,在启动的时候报如下错,使用的是注解的方式org.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'adContentDao':Invocationofinitmethodfailed;nestedexceptionisjava.lang.IllegalArgumentException:'sessionFactory'or'hibernateTemplate'isrequiredatorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1362)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:540)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:485)atjava.security.AccessController.doPrivileged(NativeMethod)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:455)atorg.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:251)atorg.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:169)atorg.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:248)atorg.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:170)atorg.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:413)atorg.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:735)atorg.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:369)atorg.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:251)atorg.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:190)atorg.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)atorg.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4992)atorg.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5490)atorg.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)atorg.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1575)atorg.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1565)atjava.util.concurrent.FutureTask.run(FutureTask.java:262)atjava.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)atjava.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)atjava.lang.Thread.run(Thread.java:745)Causedby:java.lang.IllegalArgumentException:'sessionFactory'or'hibernateTemplate'isrequiredatorg.springframework.orm.hibernate3.support.HibernateDaoSupport.checkDaoConfig(HibernateDaoSupport.java:115)atorg.springframework.dao.support.DaoSupport.afterPropertiesSet(DaoSupport.java:44)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1390)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1359)...23more
解决方案
解决方案二:
用Spring的构造方法注入'sessionFactory'or'hibernateTemplate'。
解决方案三:
引用1楼missMeyo的回复:
用Spring的构造方法注入'sessionFactory'or'hibernateTemplate'。
新手具体怎么做呢,我有一个BaseDao
解决方案四:
既然继承了HibernateDaoSupport,那么你可以这么做:@Autowiredpublicvoidinit(SessionFactorysessionFactory){this.setSessionFactory(sessionFactory);}在Spring的配置文件中配置sessionFactory即可(不知道如何配置请网上查找示例)!