spring hibernate-org.springframework.beans.factory.BeanCreationException

问题描述

org.springframework.beans.factory.BeanCreationException
applicationContext.xml文件

<?xml version=""1.0"" encoding=""UTF-8""?>
xmlns=""http://www.springframework.org/schema/beans""
xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""
xmlns:p=""http://www.springframework.org/schema/p""
xmlns:context=""http://www.springframework.org/schema/context""
xmlns:aop=""http://www.springframework.org/schema/aop""
xsi:schemaLocation=""http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"">

<bean id=""optlogger"" class=""com.log.OptLogger""></bean><aop:config>    <aop:pointcut expression=""within(com.dao.*)"" id=""servicePointcut""/>        <aop:aspect id=""optLoggerAspect"" ref=""optlogger"">        <aop:around method=""logger"" pointcut-ref=""servicePointcut""/>    </aop:aspect> </aop:config><bean id=""sessionFactory""    class=""org.springframework.orm.hibernate3.LocalSessionFactoryBean"">    <property name=""dataSource"" ref=""dataSource""></property>    <property name=""mappingResources"">        <list>             <value>com/entity/User.hbm.xml</value>         </list>    </property>    <property name=""hibernateProperties"">        <props>            <prop key=""hibernate.dialect"">                org.hibernate.dialect.MySQLDialect            </prop>        </props>    </property></bean><bean id=""hibernateuserdao"" class=""com.dao.HibernateUserDao"" init-method="""">    <property name=""sessionfactory"" ref=""sessionFactory""></property></bean></beans>

HibernateUserDao文件

public class HibernateUserDao extends HibernateDaoSupport implements UserDao{
SessionFactory sessionfactory;

public SessionFactory getSessionfactory() {    return sessionfactory;}public void setSessionfactory(SessionFactory sessionfactory) {    this.sessionfactory = sessionfactory;}public int count() {    // TODO Auto-generated method stub    String sql=""select count(*) from user"";    List list=this.getHibernateTemplate().find(sql);    return Integer.valueOf(list.get(0).toString());}public void delete(int id) {    // TODO Auto-generated method stub    User user=findByID(id);    this.getHibernateTemplate().delete(user);}public List<User> findAll() {    // TODO Auto-generated method stub    String sql=""from user"";    return this.getHibernateTemplate().find(sql);}public User findByID(int id) {    // TODO Auto-generated method stub    String sql=""from user where id=?"";    List list=this.getHibernateTemplate().find(sqlnew Object[]{id});    if(!list.isEmpty()){        return (User)list.get(0);       }    return null;}public void save(User user) {    // TODO Auto-generated method stub    this.getHibernateTemplate().save(user);}public void update(User user) {    // TODO Auto-generated method stub    this.getHibernateTemplate().update(user);}

}
报错 :

Exception in thread ""main"" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateuserdao' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is required
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1455)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:83)
at com.test.Test1.main(Test1.java:20)
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:1514)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)
... 12 more

时间: 2025-01-20 23:59:02

spring hibernate-org.springframework.beans.factory.BeanCreationException的相关文章

急死人了,SSH整合报错,高手进来帮忙解决啊,org.springframework.beans.factory.BeanCreationException

问题描述 2010-11-13 12:37:39 org.apache.catalina.core.AprLifecycleListener init信息: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: D:InstalledMyEclipsebin;D:In

ssh整合出错:org.springframework.beans.factory.BeanCreationException: Error creating

问题描述 applicationContent.xml配置<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://w

跪求大神帮解决org.springframework.beans.factory.BeanCreationException: Error creating b

问题描述 org.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor#0':Initializationofbeanfailed;nestedexceptionisorg.springframework.beans.factory.Be

javase-关于Myeclipse的错误org.springframework.beans.factory.BeanCreationException

问题描述 关于Myeclipse的错误org.springframework.beans.factory.BeanCreationException 严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListenerorg.springframework.beans.factory.BeanCreati

求解决org.springframework.beans.factory.BeanCreationException

问题描述 dwr和spring整合时出的问题,请问有谁知道这是怎么回事呢? 具体代码如下: dwr.xml <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 2.0//EN" "http://getahead.org/dwr/dwr20.dtd">

求解:org.springframework.beans.factory.BeanCreationException

问题描述 配置文件<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframew

springmvc-org.springframework.beans.factory.BeanCreationException:

问题描述 org.springframework.beans.factory.BeanCreationException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService' defined in class path resource [application.xml]: Error setting property values; nested

org.springframework.beans.factory.BeanCreationException: Error creating bean wit

问题描述 org.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'txEasyjwebProcessorAdvice':Cannotresolvereferencetobean'transactionManager'whilesettingbeanproperty'transactionManager';nestedexceptionisorg.springframework.beans.

ibatis和Spring整合抛org.springframework.beans.factory.BeanCreationException

问题描述 『spring2.5和Ibatis2整合』spring配置文件如下:<?xmlversion="1.0"encoding="UTF-8"?><beansxmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:p="http://