-
Notifications
You must be signed in to change notification settings - Fork 41.1k
Make it easier to apply customisations to the SpringApplication created by @SpringBootTest #22405
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
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 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. |
One possible idea we discussed was something like this: public interface SpringApplicationCustomizer {
void customize(SpringApplication application)
} @SpringApplication(customizer=Foo.class)
public class MyApp {
} |
As #24583 got closed as duplicate I would like to expand this issue's scope to support context hierarchies. |
@OLibutzki Any customizations that are made to a |
Add a new `useMainMethod` attribute to `SpringBootTest` which can be used to determine how the test should run. The three available options are: - `ALWAYS` - `NEVER` - `WHEN_AVAILABLE` The default is `WHEN_AVAILABLE` which will attempt to launch the test using the `main` method if there is one. The `SpringBootContextLoader` has been updated to use the new `SpringApplicationHook` interface when the main method is being used. Closes spring-projectsgh-22405
Add a new `useMainMethod` attribute to `SpringBootTest` which can be used to determine how the test should run. The three available options are: - `ALWAYS` - `NEVER` - `WHEN_AVAILABLE` The default is `WHEN_AVAILABLE` which will attempt to launch the test using the `main` method if there is one. The `SpringBootContextLoader` has been updated to use the new `SpringApplicationHook` interface when the main method is being used. Closes spring-projectsgh-22405
Refine `SpringBootContextLoader` so that calls to the main method do not exit early and the hook is only used when necessary. See gh-22405
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-classingSpringBootContextLoader
, you can't get hold of theSpringApplication
without jumping through some hoops. It's possible via a listener and theApplicationEnvironmentPreparedEvent
but that feels harder than it should.Related: #22379, #15077
The text was updated successfully, but these errors were encountered: