SSH运行时sessionFactory报错

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Property 'sessionFactory' is required
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1568)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:540)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:229)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:725)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:83)
at com.ffour.yixing.action.YixingUserInfoLogin.(YixingUserInfoLogin.java:22)
at com.ffour.yixing.action.YixingUserInfoLogin.main(YixingUserInfoLogin.java:49)
Caused by: java.lang.IllegalArgumentException: Property 'sessionFactory' is required
at org.springframework.orm.hibernate4.HibernateTransactionManager.afterPropertiesSet(HibernateTransactionManager.java:330)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1627)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1564)
... 13 more

ssh

5个回答

at com.ffour.yixing.action.YixingUserInfoLogin.(YixingUserInfoLogin.java:22)
at com.ffour.yixing.action.YixingUserInfoLogin.main(YixingUserInfoLogin.java:49)
Caused by: java.lang.IllegalArgumentException: Property 'sessionFactory' is required
这三句是重点,YixingUserInfoLogin里面的数据,然后
Error creating bean with name 'transactionManager' defined in class path resource [applicationContext.xml]
创建bean出错,看看transactionManager的class是否在applicationContext.xml写正确了

liangzi321321
二哈大叔 我的transactionManager是这样配置的 <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> <property name="dataSource" ref="dataSource"/> </bean>
2 年多之前 回复

哪位能帮帮我,求教。

http://blog.csdn.net/zzhao114/article/details/54913879 你的应该是spring事务那一块的配置上有点问题 还有就是获取数据源没有获得

我的applicationContext.xml是这样配置的,麻烦各位看看有什么问题么
<?xml version="1.0" encoding="UTF-8" ?>
xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
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/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

<!-- 上下文注释配置 -->
<context:annotation-config />
<context:component-scan base-package="com.ffour" />  
<!-- 引入项目配置属性文件 -->  
<context:property-placeholder location="classpath:db.properties" /> 
<!-- 配置数据源 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <!-- 数据库驱动类 -->
    <property name="driverClassName" value="${database.driverClassName}" />
    <property name="url" value="${database.url}" />
    <property name="username" value="${database.username}" />
    <property name="password" value="${database.password}" />
</bean>

<!-- 会话工厂 -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="configLocation" value="classpath:hibernate.cfg.xml" />
<!-- <property name="configurationClass" value="org.hibernate.cfg.AnnotationConfiguration" />  -->  
    <property name="hibernateProperties">
        <value>
            <!-- 设置数据库方言 -->
            org.hibernate.dialect.Oracle10gDialect
            <!-- 是否在控制台显示sql -->
            hibernate.show_sql=true
            <!-- 是否格式化sql,优化显示 -->
            hibernate.format_sql=true
            <!-- 是否开启二级缓存 -->
            hibernate.cache.use_second_level_cache=false
            <!-- 是否开启查询缓存 -->
            hibernate.cache.use_query_cache=false
            <!-- 数据库批量查询最大数 -->
            hibernate.jdbc.fetch_size=50
            <!-- 数据库批量更新、添加、删除操作最大数 -->
            hibernate.jdbc.batch_size=50
            <!-- 是否自动提交事务 -->
            hibernate.connection.autocommit=true
            <!-- 指定hibernate在何时释放JDBC连接 -->
            hibernate.connection.release_mode=auto
            <!-- 创建session方式 hibernate4.x 的方式 -->
            hibernate.current_session_context_class=org.springframework.orm.hibernate4.SpringSessionContext
            <!-- javax.persistence.validation.mode默认情况下是auto的,就是说如果不设置的话它是会自动去你的classpath下面找一个bean-validation**包 
                所以把它设置为none即可 -->
            javax.persistence.validation.mode=none
        </value>
    </property>
    <!-- 自动扫描实体对象 tdxy.bean的包结构中存放实体类 -->
    <!-- <property name="packagesToScan" value="tdxy.bean" /> -->
</bean>


<!-- 上下文组件扫描 -->
<context:component-scan base-package="com.ffour.yixing"></context:component-scan>
<!-- 定义事务管理器 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
    <property name="dataSource" ref="dataSource"/>
</bean>

<tx:advice id="txAdvice" transaction-manager="transactionManager">  
   <tx:attributes>  
       <tx:method name="get*" propagation="REQUIRED" read-only="true" />  
       <tx:method name="find*" propagation="REQUIRED" read-only="true" />  
       <tx:method name="list*" propagation="REQUIRED" read-only="true" />  
       <tx:method name="load*" propagation="REQUIRED" read-only="true" />  
       <tx:method name="select*" propagation="REQUIRED" read-only="true" />  
       <tx:method name="save*" propagation="REQUIRED" rollback-for="Exception"/>  
       <tx:method name="add*" propagation="REQUIRED" rollback-for="Exception"/>  
       <tx:method name="update*" propagation="REQUIRED" rollback-for="Exception"/>  
       <tx:method name="delete*" propagation="REQUIRED" rollback-for="Exception"/>  
       <!-- 其他方法使用默认的事务设置 -->  
       <tx:method name="*" propagation="REQUIRED"/>  
   </tx:attributes>
</tx:advice>

<aop:config>  
    <aop:pointcut id="interceptorPointCuts"
        expression="execution(* com.ffour.yixing.service.impl.*Impl.*(..))" />  
    <aop:advisor advice-ref="txAdvice"  
        pointcut-ref="interceptorPointCuts" />          
</aop:config>    

<bean id="yixingBaseService" class="com.ffour.yixing.service.impl.YixingBaseImpl"></bean>

忘记结贴了,找到原因了,是因为在applicationContext.xml配错了,在配置transactionManager的时候再加一个参数就对了

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!