<?xml version="1.0" encoding="UTF-8"?><!--
  - Application context definition for JPetStore's business layer.
  - Contains bean references to the transaction manager and to the DAOs in
  - dataAccessContext-local/jta.xml (see web.xml's "contextConfigLocation").
  -->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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-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">

<!-- 配置sessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
</bean>           

<!-- 配置事务管理器 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>

<!-- 配置事务的传播特性 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED"/>
<tx:method name="modify*" propagation="REQUIRED"/>
<tx:method name="*" read-only="false"/>
</tx:attributes>
</tx:advice>

<!-- 那些类的哪些方法参与事务 -->
<aop:config>
<aop:advisor pointcut="execution(* com.oa.manager.*.*(..))" advice-ref="txAdvice"/>
</aop:config>

</beans>大家好,这是好像是三大框架整合以后的一个配置文件。我就知道第一个sessionFactory用来给hibernate注入sessionFactory以产生session的,其他几个是干什么的啊?求详细解释。

解决方案 »

  1.   

    是struts2+spring2+hibernate3的项目
      

  2.   

    后面几个是配置事物。使用的AOP编程,从最后一个开始看<aop:advisor pointcut="execution(* com.oa.manager.*.*(..))" advice-ref="txAdvice"/>
    配置切点,第一个*表示任意返回值,第二个*表示com.oa.manager下的任意类,第三个*表示任意方法,(..)表示任意参数,就是这个包下的所有方法。这一整句的意思是,com.oa.manager包下的所有方法都使用txAdvice建议。
    <tx:method name="add*" propagation="REQUIRED"/>这句是说com.oa.manager包下的所有以add开头的方法都是required。这个是默认值。表示如果该方法没有事物包裹就创建,否则不创建。
      

  3.   

    请问4楼,这是spring的范畴吗?还有,那能否解释下配置事物的传播特性和配置事务管理器,那边是干什么的啊?是哪块的知识?
      

  4.   

    我只知道面向切面编程是spring的
      

  5.   

    事物传播性:最主要、最常用的就是required的。其他基本用不到,你可以看看帮助文档。主要就是解决内层事物的问题。这是spring的内容