spring quartz定時器呼叫service層事務失效原因
專案中集成了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會導致這個問題就大神留言回答
相關推薦
spring quartz定時器呼叫service層事務失效原因
專案中集成了activiti配置檔案遇到一個很詭異的問題,通過url方式呼叫controller,service層事務正常,但是spring quartz定時器呼叫service層時事務失效,經過反覆測試原因是:在activiti配置檔案中又重複配置了transactionM
Spring+Quartz定時器結合呼叫service
一、Spring+Quartz定時器 1、所需JAR包: spring-context-support版本4.1.4、 quartz版本2.2.1 2、spring-scheduler.xml <?xml version="1.0" encoding="UTF-8"
spring-quartz 定時器 給targetMethod傳遞引數
今天在做一個專案的時候,要給一個定時器任務的執行方法傳遞引數,在網上找了一下資料,可以使用arguments引數: <bean id="subsidyJobDetail" class="org.springframework.scheduling.quartz
java spring-quartz定時器實現定時任務
Quartz是一個大名鼎鼎的Java版開源定時排程器,功能強悍,使用方便,下面我們看看如何使用它 一、核心概念 Quartz的原理不是很複雜,只要搞明白幾個概念,然後知道如何去啟動和關閉一個排程程式即可。 1、Job 表示一個工作,要執行的具體內容。此介面中只有一個方法 vo
Quartz定時器中Service注入時空指標問題解決
上週在做一個任務排程時,用到了Quartz定時器,用的xml配置方式,隨後進行資料庫操作時,發現service注入不進去,報空指標錯誤,然後網上查了一些資料,找到了一個比較好的解決方法,詳情如下: 1. 問題:用qu
Spring使用定時器時無法獲取事務問題
本人Spring菜鳥,當我使用Springcloud+redis佇列時,我在其中一個模組啟動定時器定時從Redis中取資料更新至資料庫,出現了TransactionRequiredException,解決方ran案是在做更新操作的service層的方法上加上@Transac
spring quartz定時器
1.引入quartz.jar包;如果使用的maven引入方式: <dependency><groupId>org.quartz-scheduler</groupId>
spring quartz定時器配置-JobStoreTX方式持久化在資料庫中
配置quartz持久化在資料庫中,同樣需要以下三步配置,如下: 首先需要引入quartz所依賴的jar包 建立quartz_jobs.xml檔案用於配置排程器 引入quartz_jobs.xml 只是在為quartz定時器配置資料庫時,在quartz_jobs.xm
定時器 獲取 service層
application <bean name="systemJob" class="org.springframework.scheduling.quartz.JobDetailBean"> <property name="jobClass
Spring Quartz定時器
而在Spring裡很好的集成了Quartz,在xml檔案裡面配一下時間就可以自動執行,不需要寫一行程式碼。 Xml程式碼 <bean id="methodInvokingJobDetail" class="org.springframework
Spring quartz定時器不報錯,但不執行
原理現在我還沒有太搞懂,可能是因為專案執行緒併發量太少導致。 解決方法: <bean id="helloJob" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryB
spring quartz定時器--SimpleTriggerFactoryBean與CronTriggerFactoryBean
需求: 1.執行後,將mysql的資料同步到redis和(Spring建立)記憶體中的map 2.定時器每秒將redis修改的資料同步到map和mysql 一開始用監聽器(ContextLoaderListener)來調同步方法完成需求1, 由於監聽器無
spring + quartz定時器
最近在專案中遇到了一個問題,就是專案在部署到伺服器的時候,啟動完成之後,定義的定時任務會出現執行兩次的情況,比如有三個方法:a,b,c,通過檢視發現他的執行順序是,a,a,b,b,c,c,當然也有a,b,b,a,cc之類的,總之是執行了兩次。通過網上查詢發現幾種情況。在此帖
spring整合Quartz定時器
() void java類 info throws tex execute new protect 第一種:為普通java類中的某個方法配置跑批任務 1.定義要跑批的類和方法: package com.xy.utils.quartz; import org.joda.t
Spring 通過定時器 通過反射 Resource Dao層為空
技術分享 方法 img global getbean code oba 技術 需要 通過定時器,調用方法,方法中需要用到Dao層實體,Resource時為空 跟換Dao的註入方式: 從 Resource 改為 GlobalFunction.getBeanByName()即可
java定時器、Spring定時器和Quartz定時器
當前java程式中能夠實現定時的主要有三種方式,分別是:java定時器,spring定時器,quartz定時器。 下面依次講講他們的應用! java定時器的應用 其實java很早就有解決定時器任務的方法了,ja
Quartz定時器使用-spring整合方式
Spring中使用Quartz的3種方法(MethodInvokingJobDetailFactoryBean,implements Job,extends QuartzJobBean) 動態啟動,暫定,新增,刪除定時功能,可傳引數 Quartz是一個強大的企業級任務排程框架,Spr
Quartz定時器使用-非spring方式
1.建立工作的物件,實現job介面 //定義工作的類 public class HelloWorld implements Job{ public void execute(JobExecutionContext arg0) throws JobExecutionExcepti
spring service層事務管理小結
前言: 選擇spring作為開發的框架,很大一部分因素是spring框架完善的事務處理機制,spring的事務實現主要分為兩種,一種是基於Dao層,另一種是基於Service層,前者是針對單個dao的持久化操作做了事務控制,控制粒度比較小,後者則是基於業務的原則性需求,將一個原子性業務的
spring+quartz定時任務出現重複呼叫
出現問題的原因: 應該都是將quartz配置和spring配置放在了同一個xml檔案中,導致被容器掃描了兩次 如何解決呢? 其實你看了會覺得so easy 將quartz配置單獨放在一個xml檔案中,在web.xml中進行配置即可 1、新建quartz配置x