Spring Boot 3.2 allows starting the application from a main method defined in the test scope. For example:
@TestConfiguration(proxyBeanMethods = false)
class TestBootstrap {
@Bean
@ServiceConnection
@RestartScope
fun mongoDbContainer() = MongoDBContainer("mongo:4.2.8")
}
fun main(args: Array<String>) {
fromApplication<Bootstrap>().with(TestBootstrap::class).run(*args)
}
Normally from command-line Maven, you can start a spring boot application like this:
$ mvn spring-boot:run
But this will run the main
method defined in the Bootstrap
class which doesn't start the docker container. I want to run the main method from "test" that loads the TestBoostrap
configuration. How can I do this from command-line using Maven?
I found out how to do it:
$ mvn spring-boot:test-run