spring quartz定时器调用service层事务失效原因

18 篇文章 0 订阅

项目中集成了activiti配置文件遇到一个很诡异的问题,通过url方式调用controller,service层事务正常,但是spring quartz定时器调用service层时事务失效,经过反复测试原因是:在activiti配置文件中又重复配置了transactionManager导致这个问题,解决办法去掉activit-content.xml配置文件中的transactionManager配置

去掉transactionManager配置前的activiti-content.xml配置文件:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">

	<bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">

		<property name="dataSource" ref="dataSource" />
        
        <property name="transactionManager" ref="transactionManager" />
        <property name="databaseSchemaUpdate" value="true" />
        <property name="jpaEntityManagerFactory" ref="entityManagerFactory" />
        <property name="jpaHandleTransaction" value="true" />
        <property name="jpaCloseEntityManager" value="true" />
        <property name="jobExecutorActivate" value="false" />
        <property name="activityFontName" value="宋体"/>
		<property name="labelFontName" value="宋体"/>
		<property name="annotationFontName" value="宋体"/>
	
	</bean>

	<bean id="objectMapper" class="com.fasterxml.jackson.databind.ObjectMapper"/>
	
	 
	
	<bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
	
		<property name="processEngineConfiguration" ref="processEngineConfiguration" />
	
	</bean>

 

	<bean id="repositoryService" factory-bean="processEngine"
	
	factory-method="getRepositoryService" />
	
	<bean id="runtimeService" factory-bean="processEngine"
	
	factory-method="getRuntimeService" />
	
	<bean id="taskService" factory-bean="processEngine"
	
	factory-method="getTaskService" />
	
	<bean id="historyService" factory-bean="processEngine"
	
	factory-method="getHistoryService" />
	
	<bean id="managementService" factory-bean="processEngine"
	
	factory-method="getManagementService" />
	
	<bean id="identityService" factory-bean="processEngine"
	
	factory-method="getIdentityService" />
	
	<bean id="transactionManager"
	
	class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
	
	<property name="dataSource" ref="dataSource" />
	
	</bean>
	
</beans>

去掉transactionManager配置后的activiti-content.xml配置文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">

	<bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">

		<property name="dataSource" ref="dataSource" />
        
        <property name="transactionManager" ref="transactionManager" />
        <property name="databaseSchemaUpdate" value="true" />
        <property name="jpaEntityManagerFactory" ref="entityManagerFactory" />
        <property name="jpaHandleTransaction" value="true" />
        <property name="jpaCloseEntityManager" value="true" />
        <property name="jobExecutorActivate" value="false" />
        <property name="activityFontName" value="宋体"/>
		<property name="labelFontName" value="宋体"/>
		<property name="annotationFontName" value="宋体"/>
	
	</bean>

	<bean id="objectMapper" class="com.fasterxml.jackson.databind.ObjectMapper"/>
	
	 
	
	<bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
	
		<property name="processEngineConfiguration" ref="processEngineConfiguration" />
	
	</bean>

 

	<bean id="repositoryService" factory-bean="processEngine"
	
	factory-method="getRepositoryService" />
	
	<bean id="runtimeService" factory-bean="processEngine"
	
	factory-method="getRuntimeService" />
	
	<bean id="taskService" factory-bean="processEngine"
	
	factory-method="getTaskService" />
	
	<bean id="historyService" factory-bean="processEngine"
	
	factory-method="getHistoryService" />
	
	<bean id="managementService" factory-bean="processEngine"
	
	factory-method="getManagementService" />
	
	<bean id="identityService" factory-bean="processEngine"
	
	factory-method="getIdentityService" />
	
	<!-- <bean id="transactionManager"
	
	class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
	
	<property name="dataSource" ref="dataSource" />
	
	</bean> -->
	
</beans>

本人作为spring菜鸟,还不知道为啥重复配置transactionManager会导致这个问题就大神留言回答

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值