配置spring的事务管理

spring 事务管理配置 一般的,我们把事务配在service层,利用service的业务逻辑接口统一的管理。 为什么不用在dao层呢? 因为一个service有可能调用多个dao,而这多个dao有可能相互联系,有时候一个操作需要调用多次数据库,但是这多次调用要么全提交,要么全回滚。  因此,在dao层调用事务理论上说不是一个很明智的选择。应该有业务逻辑层service层负责事务,统一处理。  Spring 阅读详情
 

网上看到过很多关于spring事务管理的东西,但是原创的并不多,如果你的运气好能看到那些原创的文章恭喜你,因为我看到的不多,但一些原创的文 章里面枝叶太多,因为那些高手直接把自己的代码拷过来,所以说无疑给一些初学者或一些目前知识面有限的读者带来了很大的困难,本人就去掉枝叶,只给主干

1,配置sessionFactory

<bean id="sessionFactory" class="org.springframwork.orm.hibernate3.LocalSessionFactory">

  <property name="configLocation">

    <ref bean="classpath:hibernate.cfg.xml" />

  </property>

</bean>

2,配置事务控制器

<bean id="transactionManager"      class="org.springframework.orm.hibernate3.HibernateSessionFactoryBean">

  <property name="sessionFactory" ref="sessionFactory">

</bean>

3,配置事务的传播性

<tx:advice id="txAdvice" transaction-manager="transactionManager">

  <tx:attributes>

    <tx:method name="add*" propagation="REQUIRED" />

    <tx:method name="del*" propagation="REQUIRED" />

    <tx:method name="update*" propagation="REQUIRED" />

    <tx:mehtod name="*" read-only="true">

  </tx:attributes>

</tx:advice>

4,配置那些类的那些方法需要事务

<aop:config>

  <aop:pointcut id="allMethod" expression="execution(* com.simpl.*.*(..))" />

  <aop:advisor pointcut-ref="allMethod" advice-ref="txAdvice" />

</aop:config>

 

解释一下<execution>中的内容的意思:就是com.simp包下的所有类的所有方法,*正则表达式中的通配符,其中在包前面有一个*代表返回类型为任意类型。其中execution中的表达式可以用逻辑“或”连接多个表达式的

Spring事务管理的几种配置方式, 自己写的Spring事务管理的几种配置方式的Demo。 供新手学习! 立即下载

相关推荐

spring mvc+hibernate实现事务管理(配置文件版)

spring mvc hibernate整合,采用MyEclipse自动生成包和配置文件,jar包可能有多余,但是不影响整体效果。服务器tomcat。数据库mysql。

【Spring】— Spring的事务管理

Spring的事务管理简化了传统的事务管理流程,并且在一定程度上减少了开发者的工作量。

衍生星球的博客 3320

(一)企业微信 - 会话内容存档

企业微信获取会话记录。

专打丶小豆豆的博客 2892

Spring 事务管理方案和事务管理器及事务控制的API

Spring 事务管理方案和事务管理器及事务控制的API

qq_53317005的博客 4993

OrthoFinder功能、流程和文件注释

OrthoFinder 的标准输出包括:直系同源组,直系同源基因,有根基因树,解析基因树,无根物种树、有根物种树,基因重复事件以及相关的统计数据。

hs6605015的博客 3046

APP抓包-代理转发绕过反代理+Xposed绕过证书校验

而这里的牛牛不止设置了反代理还设置了证书校验,一闪而过的三个数据包就是在校验证书。而proxifier工具的转发机制获取的是网络接口出口数据,相当于是在网络接口设代理。这个时候就可以在夜神打开牛牛开始抓包了,打开牛牛可以看到proxifier有夜神流量通过。关闭代理之后牛牛就正常了,可恶的牛牛啊,这样我没办法抓包啊,怎么办啊。模拟器开启代理,burp开启监听。打开牛牛app,牛牛不在报错。牛牛app检测的是系统代理,也就是在模拟器或手机上设置的代理。再在浏览器下载两个模块,在夜神安装,用来屏蔽证书校验。

xiaoheizi的博客 7531

[原]Spring事务配置的五种方式 巨全!不看后悔,一看必懂!

前段时间对Spring的事务配置做了比较深入的研究,在此之间对Spring的事务配置虽说也配置过,但是一直没有一个清楚的认识。通过这次的学习发觉Spring的事务配置只要把思路理清,还是比较好掌握的。 总结如下: Spring配置文件中关于事务配置总是由三个组成部分,分别是DataSource、TransactionManager和代理机制这三部分,无论哪种配置方式,一般...

dfu54516的博客 531

数电-基于FPGA的自动售货控制系统设计

本次数电的课程设计是设计一款基于FPGA的自动售货控制系统,因为手上暂时没有FPGA的板子,所以先采用proteus仿真进行设计,观察系统效果,等之后FPGA板子下发,再移到quartus上调试和下载。同样是自己第一次自主设计电路系统,可能在功能上不完整或者逻辑上有错误,大家多多包涵,欢迎沟通交流。

gg1067的博客 2292

Java spring - 事务管理

spring-事务,呕心沥血的细节和作者内心对话!

Garson的博客 4208

Unity3D 2022版如何一键安装Newtonsoft.Json?最新Package Manager教程

本文详细介绍了在Unity3D 2022及以上版本中,如何通过Package Manager一键安装和配置Newtonsoft.Json(Json.NET)。教程涵盖了从打开Package Manager、搜索并安装正确包源,到验证安装和基础使用的完整流程,旨在帮助开发者以现代化、可靠的方式集成这一强大的JSON处理框架,提升开发效率并规避手动导入的常见问题。

lg888的博客 921

Qt5.12.12安卓开发环境搭建:Windows下避开SDK版本坑的保姆级教程

本文提供Qt5.12.12在Windows下搭建Android开发环境的详细教程,重点解决SDK版本兼容性问题,特别是cmdline-tools与JDK8的匹配陷阱。通过精准选择组件版本、手动配置路径和修复常见错误,帮助开发者高效完成环境配置,适用于Qt跨平台移动开发。

weixin_33737774的博客 542

Spring事务的使用配置和详细介绍( 编程式事务+声明式事务+隔离级别+传播行为+回滚机制)

Spring框架中的事务 有很多人觉得我们有了Spring,就再也不需要去处理获得连接、事务提交、回滚和关闭连接等这些操作了,其实并不是这样的,事实上Spring并不是直接管理事务的,只是提供了多种事务管理器,让持久化机制所提供的平台框架的事务来实现事务管理。 Spring事务管理的三大接口底层的实现关系如图所示: 三者的关系非常清晰,TransactionDefinition 将 Tran...

m0_46193073的博客 3688

【TC397第2篇】TC397 EB MCAL开发指南:ADS MCAL Demo集成深度解析

通过本文的指导,我们完成了TC397 EB MCAL与ADS的深度集成,并成功运行了一个简单的MCAL Demo。这个案例不仅帮助我们理解了MCAL在实际开发中的应用,同时也展示了ADS作为一个强大的开发工具在嵌入式系统开发中的优势。在接下来的系列文章中,我们将进一步探讨MCAL的高级应用、优化技巧以及更多实用的开发案例。敬请关注,共同探索TC397 EB MCAL开发的更多精彩!

一直在水些技术小文 452

spring的事务管理配置

spring的事务管理 注意:spring 不提供事务管理的方法,它只是提供了一个事务管理的平台 1、使用全 xml 文件配置 需要使用 AOP 技术,将事务管理注入到目标方法 ①配置切面对象,transatranctionManager,并将 dataSource 注入 ②配置通知,用于指定事务隔离级别,传播行为等 ③AOP配置,配置切入点,绑定通知 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.spri

weixin_44832570的博客 213

AgentScope 实战训练营-构建元规划智能体(Meta Planner Agent)—— 从 0 到 1 完整实现

本文介绍了基于AgentScope框架开发的元规划智能体(Meta Planner Agent)系统。该系统通过任务拆解和子代理编排机制,实现复杂任务的自动化处理。核心架构分为用户层、规划器层和子代理层,其中规划器作为"项目经理"负责任务分解、创建子代理并协调执行流程。关键技术包括AgentScope多智能体框架、DashScope大语言模型、PlanNotebook计划管理工具等。

program哲学 359

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

记spring事务管理的配置

记录下spring配置类相关注解和设置,了解导入依赖的作用。

m0_59250245的博客 1288

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

spring事务管理配置

Spring事务主要有两种配置方式:一种是基于注解配置,另一种是基于配置文件。 1.     注解配置 1)    Spring配置文件 首先需要在spring配置文件当中添加事务管理容器:   再加入事务之前一定要先排除Controller类不被事务扫描装配,此时service还没有进行事务增强处理,得到的将是原样的Service(没有经过事务加强处理,故而没有事务处理能力),

我是程序猿 8514

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

Spring事务管理器配置两种配置方法,使用方法

事务管理器配置两种配置方法,使用方法

Stardust_fantasy的博客 4641

spring事务管理xml文件的配置

spring事务管理xml文件的配置(基于xml) <?xml version="1.0" encoding="UTF-8"?> <!-- 开启包扫描 --> <context:component-scan base-package="com.yr"/> <!-- 配置数据源 --> <bean id="dataSo...

qq_41478318的博客 288

Spring之XML 配置AOP 事务管理

XML中配置AOP 切面类 正常写通知 不用加注解 public class MyAspect { //前置通知 public void mybefore(){ System.out.println("前置通知"); } //后置通知 public void myaftereturning(Object obj){ System.out.println("后置通知"); } //环绕通知 ....

少年你真的要止步于此嘛。 1093

Spring配置事务管理和简化事务配置

一.使用TransactionProxyFactoryBean创建事务代理(通常事务代理以Service层为目标bean)          PROPAGATION_REQUIRED,-MyCheckedException             PROPAGATION_REQUIRED PROPAGATION_REQU

congcongsuiyue的专栏 3358

Spring事务管理——AOP配置

说明 平时学习Spring很少用到AOP这个功能,不过这个功能对Spring事务管理有一定的作用。发现真正在用的时候自己配环境的情况特别少,都是在别人配好环境的情况下就开始用了。所以更加要记录一下配置环境的过程啊。这里用一个转账实例来说明。 下面是废话,不想看可以跳过。 最近发现进一个月来跟别人无意义的交流变多了,感觉自己说了很多没有用的话,一直在消耗,没有输入。所以这个周末都是尽量不看手机,不跟...

hansmu的博客 753

Spring之事务管理配置

1. 基于注解的事务配置   1. 在需要添加事务的方法上加上@Transactional注解   2. Spring的配置文件中配置事务管理器      1 <!-- 添加事务管理器组件DataSourceTransactionManager --> 2 <bean id="transactionManager" 3 cla...

weixin_30245867的博客 189

spring使用声明式事务管理之注解方式配置事务管理

使用注解方式配置事务管理只要在所有service层类前面加上@Transactional注解和在beans.xml中加入下面这句话 &lt;!--开启事务控制的注解支持--&gt; &lt;tx:annotation-driventransaction-manager="transactionManager"/&gt; beans.xml文件 &lt;?xml ve...

qq_40135955的博客 479
上一篇: spring事务管理
下一篇: jbpm流程发布
java_min
博客等级 码龄18年 61粉丝 161原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值