Skip to content

Make it easier to apply customisations to the SpringApplication created by @SpringBootTest #22405

Closed
@wilkinsona

Description

@wilkinsona
Member

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.

Related: #22379, #15077

Activity

snicoll

snicoll commented on Jul 22, 2020

@snicoll
Member

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 that SpringBootContextLoader 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

philwebb commented on Jul 27, 2020

@philwebb
Member

One possible idea we discussed was something like this:

public interface SpringApplicationCustomizer {
    void customize(SpringApplication application)
}
@SpringApplication(customizer=Foo.class)
public class MyApp {
}
added this to the 3.x milestone on Jul 27, 2020
OLibutzki

OLibutzki commented on Jan 6, 2021

@OLibutzki

As #24583 got closed as duplicate I would like to expand this issue's scope to support context hierarchies.

wilkinsona

wilkinsona commented on Jan 7, 2021

@wilkinsona
MemberAuthor

@OLibutzki Any customizations that are made to a SpringApplication, either directly or via SpringApplicationBuilder, are in scope for this issue. That includes context hierarchies.

added 2 commits that reference this issue on Sep 13, 2022
fdc6963
7dc99a0
modified the milestones: 3.x, 3.0.0-M5 on Sep 15, 2022
removed
status: blockedAn issue that's blocked on an external project change
on Sep 15, 2022
added 2 commits that reference this issue on Sep 15, 2022
added a commit that references this issue on Oct 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @scottfrederick@snicoll@philwebb@wilkinsona@OLibutzki

        Issue actions

          Make it easier to apply customisations to the SpringApplication created by @SpringBootTest · Issue #22405 · spring-projects/spring-boot