A @BootstrapWith annotation should be considered an override for @BootstrapWith meta-annotations not only when the @BootstrapWith annotation is directly present on the test class but also if it is present on the an ancestor of the test class.


It is common to use a base test class such as:

@SpringBootTest
public abstract class BaseTest {
}

Annotating this BaseTest with @BootstrapWith(XXX) should not make tests extending this class fail with java.lang.IllegalStateException: Configuration error: found multiple declarations of @BootstrapWith but instead properly use the @BootstrapWith as an override of the bootstrap provided as a meta-annotation by @SpringBootTest.

Comment From: pivotal-issuemaster

@antoinemeyer Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

Comment From: pivotal-issuemaster

@antoinemeyer Thank you for signing the Contributor License Agreement!

Comment From: sbrannen

Hi @antoinemeyer,

Thanks for submitting the PR.

I agree that we should improve the behavior here.

Your PR addresses the exact use case you have described; however, it allows a directly present @BootstrapWith annotation on a super-type to silently override local @BootstrapWith meta-annotations, which is not what one would expect.

For example, given the following ...

@BootstrapWith(BarBootstrapper.class)
@Retention(RetentionPolicy.RUNTIME)
@interface BootWithBar {}

@BootstrapWith(FooBootstrapper.class)
static class DirectBootstrapClass {}


@BootWithBar
static class InheritedDirectBootstrapAndLocalMetaBootstrapClass extends DirectBootstrapClass {}

... your proposal results in FooBootstrapper being used instead of BarBootstrapper or an exception.

In summary, I think we should improve the situation for your specific use case, but we'll need to investigate how best to avoid the pitfall I outlined above.

In light of that, I'm scheduling this for 6.1.x.

Comment From: sbrannen

  • superseded by #31485