spring- 'sessionFactory' or 'hibernateTemplate' is required

问题描述

'sessionFactory' or 'hibernateTemplate' is required
public class CommonDaoImpl<T> extends HibernateDaoSupport implements ICommonDao<T> {public void save(T t) {    this.getHibernateTemplate().save(t);}

// @Resource(name=""sessionFactory"")
// public final void setSessionFactoryDi(SessionFactory sessionFactory){
// super.setSessionFactory(sessionFactory);
// }

}
在这里注入sessionFactory是可以的但是我在beans.xml中注入就会报错

<bean id=""commonDaoImpl"" class=""cn.jin.elec.dao.impl.CommonDaoImpl"">    <property name=""sessionFactory"" ref=""sessionFactory""></property> </bean>

请大虾们看下到底错在哪里了

完整的错误提示是

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cn.jin.elec.dao.impl.ElecTextDaoImpl' defined in file [D:Workspacesjinelel2WebRootWEB-INFclassescnjinelecdaoimplElecTextDaoImpl.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is requiredat org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1337)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)at java.security.AccessController.doPrivileged(Native Method)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:221)at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:729)at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:381)at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)at junit.TestDao.saveElecText(TestDao.java:18)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:592)at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)at org.junit.runners.ParentRunner.run(ParentRunner.java:236)at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

Caused by: java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is required
at org.springframework.orm.hibernate3.support.HibernateDaoSupport.checkDaoConfig(HibernateDaoSupport.java:117)
at org.springframework.dao.support.DaoSupport.afterPropertiesSet(DaoSupport.java:44)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1368)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1334)
... 38 more

时间: 2024-11-03 09:31:37

spring- &amp;#39;sessionFactory&amp;#39; or &amp;#39;hibernateTemplate&amp;#39; is required的相关文章

java-关于spring+hibernate 注入sessionFactory为null的问题

问题描述 关于spring+hibernate 注入sessionFactory为null的问题 最近一个项目需要用到struts2+spring+hibernate组合框架,我在一点一点的做配置,但做到注入SessionFactory时,一直不成功,在网上搜的一些解决方案也都不适用.故在此发布,希望高手们不吝赐教.web.xml的配置为: <?xml version=""1.0"" encoding=""UTF-8""

spring mvc-No bean named &amp;amp;#39;sessionFactory&amp;amp;#39; is defined错误

问题描述 No bean named 'sessionFactory' is defined错误 运行时 报No bean named 'sessionFactory' is defined错误 我用的是Eclipse 然后是Spring MVC + Hibernate + Maven编写的0.0 解决方案 java 异常问题 No bean named 'sessionFactory' is defined:http://blog.csdn.net/mypurse/article/detail

sessionfactory-No bean named &amp;amp;#39;sessionFactory&amp;amp;#39; is defined

问题描述 No bean named 'sessionFactory' is defined 在加入spring security之后出现了下面的问题 严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener org.springframework.beans.factory.BeanCrea

hibernate spring-Error creating bean with name &amp;amp;#39;sessionFactory&amp;amp;#39;

问题描述 Error creating bean with name 'sessionFactory' 下面是详细信息2015-12-17 9:07:58 org.apache.catalina.core.StandardContext listenerStart严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextL

spring-h、s整合问题:No bean named &amp;amp;#39;sessionFactory&amp;amp;#39; is defined

问题描述 h.s整合问题:No bean named 'sessionFactory' is defined 我用的是hibernate和spring整合,在beans.xml写了sessionFactory.在类里面调用@Resource时就报错了 @Resource(name="sessionFactory") public void setSessionFactory(SessionFactory sessionFactory) { this.sessionFactory = s

Error creating bean with name &amp;#39;sessionFactory&amp;#39; defined in file

在hibernate和spring整合时,出现错误如下: Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in file [G:\workspace\s_hibernate\src\applicationContext.xml]: Invocation of

spring-Error creating bean with name &amp;amp;#39;sessionFactory&amp;amp;#39;

问题描述 Error creating bean with name 'sessionFactory' org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init metho

Error creating bean with name &amp;#39;sessionFactory&amp;#39; defined in ServletContext resource [/WEB-INF/applica

 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.io.FileNotFoun

sessionfactory-服务器启动时 No bean named &amp;amp;#39;sessionFactory&amp;amp;#39; is defined

问题描述 服务器启动时 No bean named 'sessionFactory' is defined ApplicationContext ac = WebApplicationContextUtils.getWebApplicationContext(event.getServletContext()); 每一次调用这个就会使hibernate建立一个连接池, 在applicationContext-hibernate.xml中有数据库连接信息,数据库表映射信息(sessionfacto