Spring.xml事物配置
来源:互联网 发布:广西广电网络宽带价钱 编辑:程序博客网 时间:2024/06/15 21:42
<?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"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
<!-- 定义dbcp数据源 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<!-- 指定JDBC驱动类 -->
<property name="driverClassName" value="com.mysql.jdbc.Driver">
</property>
<!-- 提供连接数据库的URL地址 -->
<property name="url"
value="jdbc:mysql://localhost:3306/db?useUnicode=true&characterEncoding=utf-8"></property>
<!-- 提供连接数据库的用户名和密码 -->
<property name="username" value="root"></property>
<property name="password" value="root"></property>
</bean>
<!--************************************************************************** -->
<!-- 定义SessionFactory Bean -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<!-- 为LocalSessionFactoryBean注入定义好的数据源 -->
<property name="dataSource">
<ref bean="dataSource" />
</property>
<!-- 添加Hibernate配置参数 -->
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
</props>
</property>
<!-- 引入com/ssh/entity/包下所有实体类对应的映射XML -->
<property name="mappingDirectoryLocations">
<list>
<value>classpath:util/</value>
</list>
</property>
</bean>
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- 配置声明式事务 -->
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="select*" read-only="true" />
<tx:method name="search*" read-only="true" />
<tx:method name="query*" read-only="true" />
<!--name="insert*" 方法名以insert开头 -->
<tx:method name="insert*" propagation="REQUIRED" />
<tx:method name="del*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="do*" propagation="REQUIRED" />
<tx:method name="*" propagation="REQUIRED" read-only="false" />
</tx:attributes>
</tx:advice>
</beans>
<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"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
<!-- 定义dbcp数据源 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<!-- 指定JDBC驱动类 -->
<property name="driverClassName" value="com.mysql.jdbc.Driver">
</property>
<!-- 提供连接数据库的URL地址 -->
<property name="url"
value="jdbc:mysql://localhost:3306/db?useUnicode=true&characterEncoding=utf-8"></property>
<!-- 提供连接数据库的用户名和密码 -->
<property name="username" value="root"></property>
<property name="password" value="root"></property>
</bean>
<!--************************************************************************** -->
<!-- 定义SessionFactory Bean -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<!-- 为LocalSessionFactoryBean注入定义好的数据源 -->
<property name="dataSource">
<ref bean="dataSource" />
</property>
<!-- 添加Hibernate配置参数 -->
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
</props>
</property>
<!-- 引入com/ssh/entity/包下所有实体类对应的映射XML -->
<property name="mappingDirectoryLocations">
<list>
<value>classpath:util/</value>
</list>
</property>
</bean>
<!-- 切面配置 -->
<aop:config>
<!-- 定义切入点 -->
<aop:pointcut id="serviceMethod" expression="execution(* dao.UserDoaImpl.*.*(..))" />
<!-- 将事务通知与切入点组合 -->
<aop:advisor advice-ref="txAdvice" pointcut-ref="serviceMethod" />
</aop:config>
<!-- 定义事务管理器 -->
<bean id="txManager"class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- 配置声明式事务 -->
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="select*" read-only="true" />
<tx:method name="search*" read-only="true" />
<tx:method name="query*" read-only="true" />
<!--name="insert*" 方法名以insert开头 -->
<tx:method name="insert*" propagation="REQUIRED" />
<tx:method name="del*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="do*" propagation="REQUIRED" />
<tx:method name="*" propagation="REQUIRED" read-only="false" />
</tx:attributes>
</tx:advice>
</beans>
阅读全文
0 0
- Spring.xml事物配置
- Spring c3p0的测试 和 事物管理 xml配置 (四)
- spring事物配置示例
- spring 配置事物
- Spring事物配置
- spring事物配置
- Spring配置事物管理
- spring 事物管理配置
- Spring的事物配置
- spring事物配置
- spring事物配置
- spring事物配置备份
- spring事物配置
- spring事物配置
- spring 事物配置
- spring事物配置
- Spring 事物配置
- Spring事物(Transaction)配置
- Java中四种引用类型
- JAVA 注解
- 自连接
- jsp中${name}这个怎么用的?
- android 网络连接的判断
- Spring.xml事物配置
- 深入理解java虚拟机
- sleep func
- Fragment加RadioGroup show和hide
- wamp解决apache服务无法开启的问题
- 使用jquery.qrcode生成二维码
- A
- 用jsoup采集福建11x5开奖结果
- Ansible常用模块介绍