2 u012491643 u012491643 于 2013.11.06 18:35 提问

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(sql,new 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

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!
其他相关推荐
springBoot:Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire fi
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.wn.boot.dao.PersonRespository com.wn.boot.test.GirlController.personRespository; nested except
Spring读取配置文件org.springframework.beans.factory.BeanCreationException异常产生的原因和解决方案
Spring读取properties文件
org.springframework.beans.factory.BeanCreationException异常的解决办法
1 异常描述在从 SVN 检出项目并配置完成后,启动 Tomcat 服务器,报出如下错误:2 异常原因通过观察上图中被标记出来的异常信息,咱们可以知道org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘XXX’此异常,为:注入 bean 失败异常。说白了,出现这个异常,就是找...
搭建SSH框架解决的小问题org.springframework.beans.factory.BeanCreationException
在以前搭建的一个SSH框架Demo在今天运行时报了如下错误信息: 严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener org.springframework.beans.factory
Caused by: org.springframework.beans.factory.BeanCreationException
1、错误原因 2014-7-13 17:36:57 org.apache.jasper.compiler.TldLocationsCache tldScanJar 信息: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete
org.springframework.beans.factory.BeanCreationException异常原因及解决办法
2013-11-15 13:59:54 org.apache.catalina.core.StandardContext listenerStart 严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderL
出现 org.springframework.beans.factory.BeanCreationException 异常的原因及解决方法
1 异常描述 在从 SVN 检出项目并配置完成后,启动 Tomcat 服务器,报出如下错误: 2 异常原因 通过观察上图中被标记出来的异常信息,咱们可以知道 org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘XXX’ 此异常,为:注入 bean 失...
ssh整合问题:启动tomcat时报错org.springframework.beans.factory.BeanCreationException
BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/classes/config/spring/spring-baseConfig.xml]: Invocation of init method failed; nes
初次整合SSH时,遇到了org.springframework.beans.factory.BeanCreationException错误
初次整合SSH时,遇到了org.springframework.beans.factory.BeanCreationException错误,在网上找了很久,一般都说jar包冲突,或者路径错误,但都不能解决我的问题,在仔细分析了报的错以后,找到了解决的办法,或许这个问题对于你们很简单,但我还是想记录下来。 环境: Eclipse  Hibernate4  spring 报的错误: org
spring 和mybatis整合时 使用context:property-placeholder载不进属性 还报org.springframework.beans.factory.BeanCrea
在spring核心配置文件(applicationContext.xml)中配置 问题:在spring 和mybatis组合时 使用该配置方式会报异常 异常为:org.springframework.beans.factory.BeanCreationExcept