spring零总
2015-07-31 11:43
561 查看
1、事务管理
2、P标签
先引入spring p标签,再进行使用,用法相当于<property>。
配置了事务管理的切面,执行过程中即使数据发生了更改,不影响数据库中的数据。只有在方法执行完成后才提交到数据库,中途发生异常,则回滚至原来状态。
<!-- 配置事务管理器 --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager" p:dataSource-ref="dataSource" /> <!-- 通过AOP配置提供事务增强,让service包下所有Bean的所有方法拥有事务 --> <aop:config proxy-target-class="true"> <aop:pointcut id="service" expression=" execution(* com.*.service.impl.*.*(..))" /> <aop:advisor pointcut-ref="service" advice-ref="txAdvice" /> </aop:config> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="select*" read-only="true" /> <!-- 以get开头的方法中的Connection是readonly的 --> <tx:method name="update*" rollback-for="Throwable"/><!-- 在update开头的方法中遇到异常(Throwable)就回滚 --> <tx:method name="delete*" rollback-for="Throwable"/><!-- 在delete开头的方法中遇到异常(Throwable)就回滚 --> <tx:method name="save*" rollback-for="Throwable"/><!-- 在save开头的方法中遇到异常(Throwable)就回滚 --> <tx:method name="add*" rollback-for="Throwable"/><!-- 在add开头的方法中遇到异常(Throwable)就回滚 --> <tx:method name="*"/> </tx:attributes> </tx:advice>
2、P标签
先引入spring p标签,再进行使用,用法相当于<property>。
<?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:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd" default-autowire="byName">
bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager" p:dataSource-ref="dataSource" />
相关文章推荐
- hadoop start-dfs.sh Error: JAVA_HOME is not set and could not be found
- java.lang.NoClassDefFoundError: org/openqa/selenium/htmlunit/HtmlUnitDriver 问题解决方案
- Java实现责任链模式
- Java压缩技术(四) GZIP——Java原生实现
- 10种常见的Java不规范代码
- springMVC 前后台日期格式传值解决方式之二(共二) @InitBinder的使用
- 使用 NIO.2 遍历目录下所有的Java文件
- struts2登陆拦截器 (FIX)
- 关于eclipse中egit右键reset失败,无法更新git仓库.
- (LeetCode)杨辉三角形Pascal's Triangle
- Eclipse 快捷键大全
- Spring MVC的@ResponseBody返回JSON串
- spring controller里模拟post提交,返回结果异常
- springMVC 前后台日期格式传值解决方式之一(共二) @DateTimeFormat的使用和配置
- 使用Spring AOP切面解决数据库读写分离
- java注解
- Lowest Common Ancestor of a Binary Search Tree Java LeetCode
- Java使用MyEclipse构建webService简单案例
- 关于Eclipse的工作空间设置默认个数和配置
- eclipse, Log4j配置(真心的详细~)