在使用springMVC时,我使用了@Service这样的注解,发现使用注解@Transactional声明的事务不起作用
问题出现的场景:
在使用spring mvc时,我使用了@Service这样的注解, 发现使用注解@Transactional声明的事务不起作用。
我的配置如下:
<mvc:annotation-driven />
<context:component-scan base-package="org.test"/ >
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<tx:annotation-driven transaction-manager="txManager" />
原因是:
component-scan和事务所在的上下文不一样,component-scan所在的配置是由servlet加载的,事务所在的配置文件是由Listener加载的。
我的解决方法:
安装下面的配置,在应用启动时,不让spring扫描到@Service注解的类
<context:component-scan base-package="org.test" >
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service" />
</context:component-scan>
在使用springMVC时,我使用了@Service这样的注解,发现使用注解@Transactional声明的事务不起作用的更多相关文章
- spring框架整合springMVC时关于AOP无法切入的问题
最开始springMVC的配置为: spring的配置为: 分析可知道spring的配置正确,由于在springmvc中已经扫描了@Controller相关的注解,所以就不需要再次扫描了,由于spri ...
- 使用springmvc时静态的文件获取不到,比如说样式丢失的问题。
当使用springmvc时前台所有的样式全部都消失不见了,查了很多资料,简单的说就是我在配置web.xml中的过滤器时将<url-pattern></url-pattern>中 ...
- 使用springmvc时处理404的方法
使用springmvc时处理404的方法 来源: https://www.cnblogs.com/handsome-man/p/5519439.html,再次申明不是我原创的,尊重原创 如何定义404 ...
- 配置springMVC时出现的问题
配置springMVC时出现的问题 项目结构如图:
- 应用springMVC时如果配置URL映射时如下配置
应用springMVC时如果配置URL映射时如下配置 [html] view plaincopy<servlet> <servlet-name>appServlet</s ...
- springMVC学习笔记(二)-----注解和非注解入门小程序
最近一直在做一个电商的项目,周末加班,忙的都没有时间更新博客了.终于在上周五上线了,可以轻松几天了.闲话不扯淡了,继续谈谈springMvc的学习. 现在,用到SpringMvc的大部分使用全注解配置 ...
- springBoot注解大全JPA注解springMVC相关注解全局异常处理
https://www.cnblogs.com/tanwei81/p/6814022.html 一.注解(annotations)列表 @SpringBootApplication:包含了@Compo ...
- Spring5:@Autowired注解、@Resource注解和@Service注解
什么是注解 传统的Spring做法是使用.xml文件来对bean进行注入或者是配置aop.事物,这么做有两个缺点: 1.如果所有的内容都配置在.xml文件中,那么.xml文件将会十分庞大:如果按需求分 ...
- SpringMVC中注解和非注解方式下的映射器和适配器总结
1. 非注解方式 1.1 处理器适配器 上一节中使用的处理器适配器是:org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapte ...
随机推荐
- 【bzoj3809/bzoj3236】Gty的二逼妹子序列/[Ahoi2013]作业 莫队算法+分块
原文地址:http://www.cnblogs.com/GXZlegend/p/6805252.html bzoj3809 题目描述 Autumn和Bakser又在研究Gty的妹子序列了!但他们遇到了 ...
- 用canvas实现鼠标拖动绘制矩形框
需要用到jCanvas插件和jQuery. jCanvas下载:https://raw.githubusercontent.com/caleb531/jcanvas/master/jcanvas.mi ...
- hashCode()方法和equals方法的重要性。
在Object中有两个重要的方法:hashCode()和equals(Object obj)方法,并且当你按ctrl+alt+s时会有Generator hashCode()和equals().我们不 ...
- Linux机器-网卡磁盘监控
1)实时监控网卡流量的通用脚本: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 ...
- parallel programming. this causual litery nots represents my recent progress in parallel programming in c#.It`s interesting.
not to say extra words,let`s start the code. pasted below: using System; using System.Collections.Ge ...
- vue v-model 与 vuex state数据绑定问题
最近开发的项目 需要用input 的v-model 直接绑定到vuex的store数据 因为v-model 能与data的数据绑定 尝试了半天 代码如下 <template> <di ...
- Linux将命令添加到PATH中【转】
转自:http://www.jb51.net/LINUXjishu/150167.html 电脑中必不可少的就是操作系统.而Linux的发展非常迅速,有赶超微软的趋势.这里介绍Linux的知识,让你学 ...
- springBoot开启热部署
springBoot开启热部署 这里使用devtools工具开启热部署 〇.搭建springbboot基础环境 一.添加依赖 <dependency> <groupId>org ...
- Javascript报错Converting circular structure to JSON 错误排解
在运行nodejs程序的时候报出以下的错误: 2017-11-20 17:44 +08:00: TypeError: Converting circular structure to JSON at ...
- Centos7下zabbix部署(四)定义报警媒介-邮件
1.安装发送邮件工具mailx [root@zabbix-server ~]# yum install mailx -y 2.自定义使用163邮箱为默认发件人(避免被当作垃圾邮件) set from= ...