当前位置: 首页 > news >正文

那曲市网站建设_网站建设公司_Logo设计_seo优化

欧洲外贸网站有哪些,未来做那个网站能致富,云服务器怎么建立网站,网站注册搜索引擎的目的在 Spring 中#xff0c;除了使用基于 XML 的方式可以实现声明式事务管理以外#xff0c;还可以通过 Annotation 注解的方式实现声明式事务管理。 使用 Annotation 的方式非常简单#xff0c;只需要在项目中做两件事#xff0c;具体如下。 1 在 Spring 容器中注册驱动除了使用基于 XML 的方式可以实现声明式事务管理以外还可以通过 Annotation 注解的方式实现声明式事务管理。 使用 Annotation 的方式非常简单只需要在项目中做两件事具体如下。 1 在 Spring 容器中注册驱动代码如下所示 tx:annotation-driven transaction-managertxManager/2 在需要使用事务的业务类或者方法中添加注解 Transactional并配置 Transactional 的参数。关于 Transactional 的参数如下图所示。 下面通过修改Spring声明式事务管理点击跳转至Spring声明式事务管理中银行转账的案例讲解如何使用 Annotation 注解的方式实现 Spring 声明式事务管理。 1. 注册驱动 修改 Spring 配置文件 applicationContext.xml修改后如下所示。 ?xml version1.0 encodingUTF-8? beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexmlns:contexthttp://www.springframework.org/schema/contextxmlns:txhttp://www.springframework.org/schema/txxmlns:aophttp://www.springframework.org/schema/aopxsi:schemaLocationhttp://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-2.5.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-2.5.xsd!-- 加载properties文件 --context:property-placeholder locationclasspath:c3p0-db.properties /!-- 配置数据源读取properties文件信息 --bean iddataSource classcom.mchange.v2.c3p0.ComboPooledDataSourceproperty namedriverClass value${jdbc.driverClass} /property namejdbcUrl value${jdbc.jdbcUrl} /property nameuser value${jdbc.user} /property namepassword value${jdbc.password} //bean!-- 配置jdbc模板 --bean idjdbcTemplate classorg.springframework.jdbc.core.JdbcTemplateproperty namedataSource refdataSource //bean!-- 配置dao --bean idaccountDao classcom.mengma.dao.impl.AccountDaoImplproperty namejdbcTemplate refjdbcTemplate //bean!-- 配置service --bean idaccountService classcom.mengma.service.impl.AccountServiceImplproperty nameaccountDao refaccountDao //bean!-- 事务管理器依赖于数据源 --bean idtxManagerclassorg.springframework.jdbc.datasource.DataSourceTransactionManagerproperty namedataSource refdataSource //bean!-- 注册事务管理驱动 --tx:annotation-driven transaction-managertxManager/ /beans上述代码中可以看出与原来的配置文件相比这里只修改了事务管理器部分新添加并注册了事务管理器的驱动。 注意在学习 AOP 注解方式开发时需要在配置文件中开启注解处理器指定扫描哪些包下的注解这里没有开启注解处理器是因为在第 3335 行手动配置了 AccountServiceImpl而 Transactional 注解就配置在该类中所以会直接生效。 2. 添加 Transactional 注解 修改 AccountServiceImpl在文件中添加 Transactional 注解及参数添加后如下所示。 package com.mengma.service.impl;import org.springframework.transaction.annotation.Isolation; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional;import com.mengma.dao.AccountDao;Transactional(propagation Propagation.REQUIRED, isolation Isolation.DEFAULT, readOnly false) public class AccountServiceImpl {private AccountDao accountDao;public void setAccountDao(AccountDao accountDao) {this.accountDao accountDao;}public void transfer(String outUser, String inUser, int money) {this.accountDao.out(outUser, money);// 模拟断电int i 1 / 0;this.accountDao.in(inUser, money);} }注意在使用 Transactional 注解时参数之间用“”进行分隔。 使用 JUnit 测试再次运行 test() 方法时控制台同样会输出如下图所示的异常信息这说明使用基于 Annotation 注解的方式同样实现了 Spring 的声明式事务管理。如果注释掉模拟断电的代码进行测试则转账操作可以正常完成。
http://www.ihoyoo.com/news/97381.html

相关文章:

  • 外贸导向企业网站免费中文WordPress主题
  • 电子商务网站建设项目规划书网站开发合同是否是技术合同
  • 优秀htm网站使用wordpress标签库
  • 深圳多语言网站建设做网站免费空间
  • 商城网站源码大全如何加入wordpress
  • 个人网站网站建设如皋网站制作
  • 为企业规划网站注意什么南宁seo内部优化
  • 网页设计最牛的网站建设上海著名网站建设
  • python做网站 教育注册网站需要多少钱
  • 滨海网站建设九江网站建设网站制作
  • 关于设计方面的网站网站如何做关键词排名
  • 如何做网站步骤不屏蔽网站的浏览器
  • 盐城网站制作哪家好云南网警在线报警
  • ace网站建设河南省住房和城乡建设厅官网证书查询
  • wordpress网站图标织梦移动端网站怎么做
  • 个人网站数据库大小医院网站建设规划
  • 扁平化网站源码网站建设数据库
  • 什么是网络营销型网站看网站的访问量
  • 福建省建设工程信息网站wordpress 网站迁移
  • 网站开发项目运营经理岗位职责杭州制作企业公司网站
  • 二手车网站怎么做莆田建站服务
  • 网站建设实习生怎么样三只松鼠网络营销方案策划书
  • 在网站建设中 为了防止工期拖延做一个页面多少钱
  • 怎么选择大连网站建设企业网站建设方案机构
  • 宇宙设计网站推荐做网站分几个步骤
  • 个人视频网站源码17网站一起做网店 发货慢
  • 常德经开区网站官网正黄集团博弘建设官方网站
  • 门户网站建设管理工作的意见网站建设方案论文
  • 视频网站开发策划书3000款免费软件app下载
  • 免费游戏网站建设网页制作与网站建设实战教程视频