<?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的,其他几个是干什么的啊?求详细解释。
- 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的,其他几个是干什么的啊?求详细解释。
配置切点,第一个*表示任意返回值,第二个*表示com.oa.manager下的任意类,第三个*表示任意方法,(..)表示任意参数,就是这个包下的所有方法。这一整句的意思是,com.oa.manager包下的所有方法都使用txAdvice建议。
<tx:method name="add*" propagation="REQUIRED"/>这句是说com.oa.manager包下的所有以add开头的方法都是required。这个是默认值。表示如果该方法没有事物包裹就创建,否则不创建。