Exception “java.lang.IllegalStateException: Existing transaction detected in JobRepository.” after upgrading spring batch from 2.1.1 to 4.1.1 version

邮差的信 提交于 2021-02-11 05:54:38

问题


I have a Junit test case which run a batch job. Previously It was working when I have spring batch version 2.1.2. But once I upgraded to version 4.1.1, am getting below exception

java.lang.IllegalStateException: Existing transaction detected in JobRepository. Please fix this and try again (e.g. remove @Transactional annotations from client).

I have tried removing @Transactional from test class. But still getting an exception.I guess the error is due to two transactions. But still removal of one didn't fix the error.

Below Annotations used in the test class and it has test methods which call the method which do batch job. I have used Transactional on the test class and the test method run with SpringJUnit4ClassRunner runner. I tried with SpringRunner too.

@RunWith(SpringJUnit4ClassRunner.class) @DirtiesContext
@Transactional

This method will be called from test method. The method launched the batch job.

@Transactional(propagation = Propagation.NOT_SUPPORTED)
public Long startExportJob(){

My spring core version is 4.3.18. Do I need to upgrade it to 5? Help me in solving this. Thanks in advance.


回答1:


My spring core version is 4.3.18. Do I need to upgrade it to 5?

Yes, Spring Batch v4 requires Spring Framework v5. Please see the What's new section of version 4.

A lot of changes have been made between v2.1 and v4.1. I recommend gradual upgrades (at least one major version at a time), otherwise you need to check the change logs and see what could be related to your test.



来源:https://stackoverflow.com/questions/54326747/exception-java-lang-illegalstateexception-existing-transaction-detected-in-job

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!