<?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:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver">
</property>
<property name="url"
value="jdbc:mysql://192.168.100.161:3306/gtt_organization">
</property>
<property name="username" value="root"></property>
<property name="password" value="root"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>
com/oa/gtt_organization/t_address/entity/TAddress.hbm.xml
</value>
</list>
</property>
</bean>
<bean id="TAddressDAO"
class="com.oa.gtt_organization.t_address.daoImpl.TAddressDAOImpl">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<!-- 声明一个 Hibernate 3 的 事务管理器供代理类自动管理事务用 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<bean id="persondaoProx"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>   
 <!-- 注意这个属性, 必须为 true 使用 CGLIB 才不用强制编写被代理类的接口 -->
<property name="proxyTargetClass">
<value>true</value>
</property>
<property name="target">
<ref local="TAddressDAO" />
</property>
<property name="transactionAttributes">
<props>    <!-- 这里的方法签名可以精确到方法, 先懒惰一下全配置上 -->
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<bean id="t_AddressAction" class="com.oa.gtt_organization.t_address.action.TAddressAction">
<property name="t_AddressDao">
<ref bean="persondaoProx" />
</property>
<!-- <property name="queryType">-->
<!-- <list>-->
<!-- <value>object</value>-->
<!-- <value>type</value>-->
<!-- <value>address</value>-->
<!-- </list>-->
<!-- </property>-->
</bean>
</beans>上面是我的Spring配置文件,标红色是出错的地方,Myeclipse提示这个连个属性找不到set方法,请哥哥们帮我看看了,都搞了1整天了,谢谢!springhibernate事物

解决方案 »

  1.   

    IDE 提示这两个属性找不到set方法,实在不知道问题出在什么地方,求大神们帮看看,灰常感谢!
      

  2.   

    org.springframework.transaction.interceptor.TransactionProxyFactoryBean
    你打开这个类的源码看看有没有这两个属性?如果没有可能就是你的jar包版本不对或是根本就是个错误的jar。
      

  3.   

    确实是的,我知道这个雷利确实没有这连个属性,这个事物的配置我是从网上别人的代码 copy过来的,我用的是spring 3.2,请问这样的话Hibernate与spring集成的事物我该怎么配呢
      

  4.   

    我原来是没有配置事物的,但是在插入数据的时候数据没有插入数据库,连SQl语句都没有,我上网查说要配置事物,所以就copy了一下别人的代码,就有了这样的问题,请高手指点,谢谢了!
      

  5.   

    TransactionProxyFactoryBean的父类是AbstractSingletonProxyFactoryBean,它有setTarget(Object)
    AbstractSingletonProxyFactoryBean的父类是ProxyConfig,它有setProxyTargetClass(boolean proxyTargetClass)
    估计LZ没有导入spring-aop.jar
      

  6.   

    谢谢,问题解决了,我换了一种配置方式,虽然问题解决了,但是对这一块还是有些不了解,因为我在自己写的测试类里是可以插入数据的,通过页面通过Action提交为什么就需要事物提交了呢,看来还得做做功课!
      

  7.   

    我现在换成了这种配置方式
    class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">

    <property name="transactionManager">
    <ref bean="myTransactionManager" />
    </property>
    <property name="target">
    <ref bean="TAddressDAO" />
    </property>
    <property name="transactionAttributes">
    <props>
    <!--  表示对所有以insert和save开头的方法  进行事务处理  -->
    <prop key="insert*">PROPAGATION_REQUIRED</prop>
    <prop key="save*">PROPAGATION_REQUIRED</prop>
    </props>
    </property>
    </bean>