Closed
Description
When creating a SpringApplication
in their application's main method, users can apply customizations to meet their needs. When these same customisations are also needed in their application's tests, reusing the same customizations isn't particularly easy. Without sub-classing SpringBootContextLoader
, you can't get hold of the SpringApplication
without jumping through some hoops. It's possible via a listener and the ApplicationEnvironmentPreparedEvent
but that feels harder than it should.
Metadata
Metadata
Assignees
Labels
Type
Projects
Relationships
Development
No branches or pull requests
Activity
snicoll commentedon Jul 22, 2020
This looks like what we're doing for the war-based deployment stuff. What if your Spring Boot Application could implement an additional interface that provides a hook point with
SpringApplicationBuilder
? When this is present the callback would be invoked to customize the application. The added-benefit is thatSpringBootContextLoader
would do too when running an integration test.The downside is that an existing application class would have to be rearranged a bit to move the customization of the builder in a dedicated method. That sounds like reasonable for those who care about such customizations.
philwebb commentedon Jul 27, 2020
One possible idea we discussed was something like this:
OLibutzki commentedon Jan 6, 2021
As #24583 got closed as duplicate I would like to expand this issue's scope to support context hierarchies.
wilkinsona commentedon Jan 7, 2021
@OLibutzki Any customizations that are made to a
SpringApplication
, either directly or viaSpringApplicationBuilder
, are in scope for this issue. That includes context hierarchies.Add SpringBootTest.useMainMethod support
Add SpringBootTest.useMainMethod support
Refine SpringBootTest.useMainMethod support
Switch @SpringBootTest to UseMainMethod.NEVER by default
Add Javadoc since for UseMainMethod