springmvc+mybatis 事务不起作用

253808086 发布于 2016/09/18 17:15
阅读 319
收藏 0
 

applicationContext.xml

<!-- 使用annotation 自动注册bean, 并保证@Required、@Autowired的属性被注入 -->
	<context:component-scan base-package="com.zf.tpc">
		<context:exclude-filter type="annotation"
			expression="org.springframework.stereotype.Controller" />
		<context:exclude-filter type="annotation"
			expression="org.springframework.web.bind.annotation.ControllerAdvice" />
	</context:component-scan>

<!-- 配置事务管理器 -->
	<bean id="transactionManager"
		class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dataSource"></property>
	</bean>

	<tx:annotation-driven transaction-manager="transactionManager"
		proxy-target-class="true" />

springmvc-xml

<!-- 自动扫描且只扫描@Controller -->
	<context:component-scan base-package="com.zf.tpc"
		use-default-filters="false">
		<context:include-filter type="annotation"
			expression="org.springframework.stereotype.Controller" />
		<context:include-filter type="annotation"
			expression="org.springframework.web.bind.annotation.ControllerAdvice" />
	</context:component-scan>

	<!-- <aop:aspectj-autoproxy proxy-target-class="true" /> -->

	<mvc:annotation-driven>
		<mvc:message-converters register-defaults="true">
			<!-- 将StringHttpMessageConverter的默认编码设为UTF-8 -->
			<bean class="org.springframework.http.converter.StringHttpMessageConverter">
				<constructor-arg value="UTF-8" />
			</bean>
			<!-- 将Jackson2HttpMessageConverter的默认格式化输出设为true -->
			<bean
				class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
				<property name="prettyPrint" value="true" />
			</bean>
		</mvc:message-converters>
	</mvc:annotation-driven>



service.java

@Transactional(rollbackFor = { Exception.class })
	public void acceptComment(Long id) throws Exception {

		 QuestionComment questionComment = new QuestionComment();
		 questionComment.setId(id);
		 questionComment.setAnswer("asdasd");

		questionCommentMapper.updateByPrimaryKeySelective(questionComment);

		throw new RuntimeException();
	}



请问各位大牛,是否我哪里配置错误了。代码都没有全部贴出来,只贴了感觉关键的部分。

事务一直不起作用,在service中更改的还是更改了。



加载中
0
求是科技
求是科技

https://my.oschina.net/u/2312022/blog/743118

现将事务配起,再逐步的添加其他的功能

返回顶部
顶部