spring mvc 注解事务不生效
来源:互联网 发布:网店刷销量软件 编辑:程序博客网 时间:2024/06/02 07:46
spring mvc注解事务配置很简单
下面简短的代码便可以解决 注解事务不生效问题。
我是 在web.xml文件<servlet-name>指向的首先加载的spring配置文件中加以下注解。这样好像不够优雅但没尝试更好的方法。
<!-- (事务管理) -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<!--定义注解驱动的事务 告诉spring查找上下文中所有@Transactional注解的Bean,
而不管注解用在类级别还是方法级别上,对于每个使用@Transactional的Bean <tx:annotation-driven>
会自动为它添加事务通知
**proxy-target-class 若service类实现了接口,其值要为true
**要想事务生效,必须要扫描包前定义注解驱动事务
-->
<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" />
<!--自动扫描注解bean -->
<context:component-scan base-package="com"/>
另外在service、controller类中都要throws Exception,例如下面
@Transactional(propagation=Propagation.REQUIRED,rollbackFor={Exception.class})
public void addSaveMoney ( BigDecimal amount,String account,DealRecord dealRecord)throws Exception{
try{
bankAccountDao.saveMoney(amount, account);
// String s = null;
// s.length();
bankAccountDao.saveOrPutMoneyLog(dealRecord);
}catch(Exception e){
throw e;
}
}
@RequestMapping(value="/saveMoney",method= RequestMethod.POST)
public ModelAndView saveMoney(HttpServletRequest request,Model model) throws Exception{
String account = request.getParameter("account");
String amountString = request.getParameter("amount");
Long amountLong = Long.valueOf(amountString);
// Long amountLong = Long.decode(amountString);
BigDecimal amount = BigDecimal.valueOf(amountLong);
Long accountid = bankAccountService.findAccountid(account);
Timestamp dealTime = TimeStampUtil.formatTimeStamp(new Timestamp(new Date().getTime()));
DealRecord dealRecord = new DealRecord(accountid, amount, DealWay.put, dealTime);
bankAccountService.addSaveMoney(amount, account,dealRecord);
return new ModelAndView(new RedirectView("../security/userInfo/"+request.getParameter("name")));
}
- spring mvc 注解事务不生效
- spring事务注解不生效
- spring mvc 事务不生效 不回滚
- spring mvc 事务不生效 不回滚
- spring结合spring mvc下用注解式事务不生效
- spring mvc 注解配置StringHttpMessageConverter不生效
- spring mvc 注解配置StringHttpMessageConverter不生效
- spring mvc 注解配置StringHttpMessageConverter不生效
- 【Spring】spring-mvc hibernate druid jdbc等数据源事务配置详解(解决注解事务不生效问题)
- spring mvc @Transaction注解不生效的解决
- spring 注解aop不生效
- Spring @Transactional注解不生效
- spring mvc事务注解
- Spring事务不生效的解决过程
- Spring事务不生效问题汇总
- 注解式事务和配置式事务同时存在,注解式事务不生效
- spring事务 方法调用内部方法 事务不生效
- spring 事务不生效或者springmvc controller映射不到
- Quartz使用总结。---在某一个有规律的时间点干某件事。
- Qt之线程同步
- 算法设计与分析HW4:LeetCode5
- log日志规范,区别
- linux指令wc/pgrep
- spring mvc 注解事务不生效
- sequel pro 连接mysql数据库遇到的问题
- spring常用注解辨析
- Java多线程系列--“基础篇”02之 常用的实现多线程的两种方式
- Android Ble 4.0 蓝牙开发交互
- ArrayList、Vector、HashMap、HashSet的默认初始容量、加载因子、扩容增量
- Java常见的几种排序算法-插入、选择、冒泡、快排、堆排等
- 一颗二叉查找树的简单实现
- c++智能指针(1)