0

I'm experiencing a R2DBC transaction management issue with (although my application runs fine through a REST controller and also a Spring WebTestClient). My model is quite simple, but I implemented entity callbacks with enforced transaction management (MANDATORY).

public interface PersonsRepository extends ReactiveCrudRepository<Person, Long> {
}
@Component
@Transactional(propagation = MANDATORY)
public class PersonSaveListener implements AfterSaveCallback<Person> {
    @Autowired
    private DatabaseClient client;
    ...
}

@SpringBootTest // with entity callbacks!
class RepositoriesTests {
    @Test
    @Transactional
    void dao_ShouldHandleRelationship() {
        Person person = personDao.save(new Person("foo", "bar", LocalDate.now())).block();
        ...
    }

Again, I guess that's just a test transaction management issue, for the application is working perfectly fine so far. I keep getting that error, though:

java.lang.IllegalStateException: Failed to retrieve PlatformTransactionManager for @Transactional test: [DefaultTestContext@2569afda testClass = RepositoriesTests, testInstance = com.example.demo.RepositoriesTests@28dd8786, testMethod = dao_ShouldHandleRelationship@RepositoriesTests, testException = [null], mergedContextConfiguration = [ReactiveWebMergedContextConfiguration@70efdd18 testClass = RepositoriesTests, locations = '{}', classes = '{class com.example.demo.DemoApplication}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}', contextCustomizers = set[org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@71a8adcf, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@659499f1, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@7d4f9aae, org.springframework.boot.test.web.reactive.server.WebTestClientContextCustomizer@783a467b, org.springframework.boot.test.autoconfigure.actuate.metrics.MetricsExportContextCustomizerFactory$DisableMetricExportContextCustomizer@242b836, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@1e0b4072, org.springframework.boot.test.context.SpringBootTestArgs@1, org.springframework.boot.test.context.SpringBootTestWebEnvironment@7f416310], contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]], attributes = map['org.springframework.test.context.event.ApplicationEventsTestExecutionListener.recordApplicationEvents' -> false]]
at org.springframework.util.Assert.state(Assert.java:97) ~[spring-core-5.3.15.jar:5.3.15]
at org.springframework.test.context.transaction.TransactionalTestExecutionListener.beforeTestMethod(TransactionalTestExecutionListener.java:224) ~[spring-test-5.3.15.jar:5.3.15]
at org.springframework.test.context.TestContextManager.beforeTestMethod(TestContextManager.java:293) ~[spring-test-5.3.15.jar:5.3.15]
at org.springframework.test.context.junit.jupiter.SpringExtension.beforeEach(SpringExtension.java:174) ~[spring-test-5.3.15.jar:5.3.15]

So my question is how do I put that PlatformTransactionManager back in for that test? Thanks for reading.

NB: I'm using Spring Boot 2.6.3 with an embedded H2 Database

Thomas Escolan
  • 1,298
  • 1
  • 10
  • 28

1 Answers1

3

I believe that R2DBC doesn't have a PlatformTransactionManager, so you can't do transactional testing like this.

See this github issue for more details: https://github.com/spring-projects/spring-framework/issues/24226

Nayan Hajratwala
  • 350
  • 1
  • 4
  • 11