1

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.

Kamil W
  • 2,230
  • 2
  • 21
  • 43
Raj
  • 103
  • 9

1 Answers1

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.

Mahmoud Ben Hassine
  • 28,519
  • 3
  • 32
  • 50