• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号
您的位置:首页 > 程序设计 >JSP > JSP 中spring事务配置详解

JSP 中spring事务配置详解

作者: 字体:[增加 减小] 来源:互联网 时间:2017-05-11

通过本文主要向大家介绍了spring boot jsp,springmvc jsp,spring mvc jsp传值,spring jsp,springmvc不拦截jsp等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

JSP 中spring事务配置详解

前几天被问到,如何防止服务器宕机,造成的数据操作的不完全。

问了一下同事,是事务。哎,恍然大悟,迷糊一时了。

声明式的事务配置,这个是最推荐的,配置到service层。

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:context="http://www.springframework.org/schema/context"
  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.xsd
  http://www.springframework.org/schema/tx
  http://www.springframework.org/schema/tx/spring-tx.xsd
  http://www.springframework.org/schema/context
  http://www.springframework.org/schema/context/spring-context.xsd
  http://www.springframework.org/schema/aop
  http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
  
  <!-- 使用annotation @Repository,@Service自动注册bean, 并保证@Required、@Autowired的属性被注入的包范围 -->
  <context:component-scan base-package="com.rd,com.rongdu"/>
  <context:annotation-config/>
  

  <bean id="dataSource" class="com.jolbox.bonecp.BoneCPDataSource" destroy-method="close">
    <!-- Connection Info -->
    <property name="driverClass" value="com.mysql.jdbc.Driver"/>
    <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/sfd?useUnicode=true&characterEncoding=utf8"/>
    <property name="username" value="root"/>
    <property name="password" value="123456"/>

    <!-- 检查数据库连接池中空闲连接的间隔时间 -->
    <property name="idleConnectionTestPeriod" value="4" />
    <!-- 连接池中未使用的链接最大存活时间 -->
    <property name="idleMaxAge" value="240" />
    <!-- 设置每个分区含有connection最大个数 -->
    <property name="maxConnectionsPerPartition" value="20" />
    <!-- 设置每个分区含有connection最小个数 -->
    <property name="minConnectionsPerPartition" value="10" />
    <!-- 设置每个分区数 -->
    <property name="partitionCount" value="3" />
    <!-- 设置分区中的connection增长数量 -->
    <property name="acquireIncrement" value="5" />
    <property name="statementsCacheSize" value="50"/>
     <property name="releaseHelperThreads" value="3"/>
  </bean>

  <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
    <property name="dataSource">
      <ref bean="dataSource" />
    </property>
  </bean>
  <bean id="namedParameterJdbcTemplate" class="org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate">
    <constructor-arg index="0" ref="dataSource"/> 
  </bean>

  <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
     <property name="dataSource" ref="dataSource"/>
  </bean>
  
  
  <tx:advice id="txAdvice" transaction-manager="txManager">
    <tx:attributes>
      <tx:method name="add*" propagation="REQUIRED" />
      <tx:method name="delete*" propagation="REQUIRED" />
      <tx:method name="update*" propagation="REQUIRED" />
      <tx:method name="*" propagation="REQUIRED" />

    </tx:attributes>
  </tx:advice>
  
  <aop:config>
    <aop:pointcut id="allManagerMethod"
      expression="execution(* com.test.service.*.*(..))" />
    <aop:advisor advice-ref="txAdvice" pointcut-ref="allManagerMethod" />
  </aop:config>
</beans>

</div>

其中,有个通配符是有点问题的。事务在于更新数据时候使用,查询不需要事务。所以直接用* ,这样太过于暴力了。

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

</div>
分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • JSP 中spring事务配置详解
  • JSP Spring ApplicationContext的国际化支持
  • JSP Spring 自动化装配Bean实例详解
  • JSP 中Spring组合注解与元注解实例详解
  • JSP 获取Spring 注入对象示例

相关文章

  • 2017-05-11Hibernate+Spring+Struts扩展Struts
  • 2017-05-11jsp文件操作之追加篇
  • 2017-05-11jsp Hibernate入门教程第1/3页
  • 2017-05-11struts2+jsp实现文件上传的方法
  • 2017-05-11jsp页面中EL表达式被当成字符串处理不显示值问题的解决方法
  • 2017-05-11JSP是什么?JSP是什么意思?
  • 2017-05-11Jquery、Ajax、Struts2完成定时刷新的方法
  • 2017-05-11JSP开发Servlet重写init()方法实例详解
  • 2017-05-11JSP application(return String)用法详例
  • 2017-05-11详解Hibernate cascade级联属性的CascadeType的用法

文章分类

  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号

最近更新的内容

    • jsp 重复提交问题
    • JSP使用Servlet作为控制器实现MVC模式实例详解
    • 实例讲解JSP Model2体系结构(中)
    • 通过JDBC连接oracle数据库的十大技巧
    • 整体刷新和局部刷新frameset窗口问题深入探讨
    • Hibernate save() saveorupdate()的用法第1/2页
    • JSP 不能解析EL表达式的解决办法
    • JSP数据分页导出下载显示进度条样式
    • 基于EJB技术的商务预订系统的开发
    • CORBA对象生命周期

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有