spring-projects / spring-boot

Spring Boot helps you to create Spring-powered, production-grade applications and services with absolute minimum fuss.
https://spring.io/projects/spring-boot
Apache License 2.0
75.43k stars 40.76k forks source link

Test and document @RestartScope with testcontainers #35200

Open philwebb opened 1 year ago

philwebb commented 1 year ago

Our testcontainers support should work with @RestartScope. It would be good to document this and have tests.

mhalbritter commented 1 year ago

I can confirm that it works. However i found #35323 while testing it. When you move the testcontainers @Configuration class into src/main/java and annotate the bean method with @RestartScope, it works with devtools and the container survives the reloading.

mhalbritter commented 1 year ago

One thing i found: When using @RestartScope, you need to change

developmentOnly 'org.springframework.boot:spring-boot-devtools'

to

testImplementation 'org.springframework.boot:spring-boot-devtools'

otherwise @RestartScope could not be found.

mhalbritter commented 1 year ago

35323 is invalid. It works when using testImplementation configuration for devtools.

mhalbritter commented 1 year ago

I've added some documentation in https://github.com/spring-projects/spring-boot/commit/1504e3043d8e134f90143239995ff141c86af7bc.