Skip to content

ApplicationContextRunner does not work correctly when AutoConfiguration class has not @Configuration #13129

Closed

Description

@filiphr

This is most definitely my error that I forgot to add an @Configuration to my custom auto configuration.

The problem occurs when an auto configuration class (e.g. MyCustomAutoConfiguration) has a nested configuration class with @EnableConfigurationProperties is missing a @Configuration (the root class) then the Spring Boot application works correctly. However, when using the ApplicationContextRunner the behaviour is not the same.

See this repository for a reproducing example. In the example repo if you move the @EnableConfigurationProperties then tests that were failing before will pass.

If you think that there is nothing that Boot can do about this, feel free to close it. I was just confused why it was working in one instance, but not in the other

Activity

  1. added
    status: waiting-for-triage
    on May 9, 2018
  2. wilkinsona commented on May 10, 2018

    @wilkinsona
    Member

    Thanks for the sample.

    The difference in behaviour is due to a difference in how MyCustomAutoConfiguration is registered with the application context. When you use @SpringBootTest it's registered via the import selector for auto-configuration and is processed as a configuration class. When you use ApplicationContextRunner it's registered via a call to org.springframework.context.annotation.AnnotationConfigRegistry.register(Class<?>...) and isn't processed in the same way. Critically, it isn't processed by ConfigurationClassParser and doesn't go through its processMemberClasses method. It's there that the nested configuration class is found when using @SpringBootTest.

  3. added
    type: bug
    for: team-attention
    and removed
    status: waiting-for-triage
    on May 10, 2018
  4. added this to the 2.0.x milestone on May 10, 2018
  5. filiphr commented on May 10, 2018

    @filiphr
    ContributorAuthor

    Thanks a lot analysis and looking into it

  6. removed
    for: team-attention
    on May 16, 2018
  7. self-assigned this
    on May 16, 2018
  8. wilkinsona commented on May 18, 2018

    @wilkinsona
    Member

    I believe this is a Spring Framework bug so I have opened SPR-16839. If the Framework team disagree we can re-open this issue and look for a workaround.

  9. removed this from the 2.0.x milestone on May 18, 2018
  10. added
    for: external-project
    and removed
    type: bug
    on May 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

for: external-project

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions