Skip to content

2.7 Changes to Auto-Configuration #197

Closed

Description

@timtebeek

https://docs.spring.io/spring-boot/docs/2.7.x/reference/html/howto.html#howto.testing.slice-tests

Auto-configuration Registration
If you have created your own auto-configurations, you should move the registration from spring.factories to a new file named META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports. Each line contains the fully qualified name of the auto-configuration. See the included auto-configurations for an example.

For backwards compatibility, entries in spring.factories will still be honored.

So:

  1. Any src/main/resources/META-INF/spring.factories file should move to META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
  2. the comma separate value for key org.springframework.boot.autoconfigure.EnableAutoConfiguration should be split across separate lines.

New @autoConfiguration Annotation
A new @autoConfiguration annotation has been introduced. It should be used to annotate top-level auto-configuration classes that are listed in the new META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports file, replacing @configuration. Configuration classes that are nested within or imported by an @autoConfiguration class should continue to use @configuration as before.

For your convenience, @autoConfiguration also supports auto-configuration ordering via the after, afterNames, before and beforeNames attributes. This can be used as a replacement for @AutoConfigureAfter and @AutoConfigureBefore.

So:

  1. Replace usage of @Configuration with @AutoConfiguration where classes are mentioned in the above replaced src/main/resources/META-INF/spring.factories

Test Slice Configuration
If you have created your own test-slices, you should move the registration from spring.factories to the new place under META-INF/spring/.imports. The format is the same as the new file described in the "Auto-configuration Registration" section, see above.

See the included test slices for an example.

Above steps are complicated even more for users defining their own test slices, requiring a different filename with the same one class per line structure as above.

Activity

  1. timtebeek commented on Jun 2, 2022

    @timtebeek
    MemberAuthor

    I'd guess somewhat lower priority as compared to other issues, as own auto configuration classes are not as often used. Typically only in company/team wide starter libraries. But still, changes like these could go unnoticed in a migration, until they break at a later date, since backwards compatibility is still there.

  2. pway99 commented on Jun 6, 2022

    @pway99
    Contributor

    Thanks @timtebeek,
    Now that unsupported file types are represented as Quarks its possible to detect and rename the file, unfortunately, it's not possible to modify Quark source contents. Perhaps this recipe could add a SearchMarker to the project pom with a message providing transformation instructions.

  3. added
    recipe
    on Jun 6, 2022
  4. moved this to Backlog in OpenRewriteon Jun 6, 2022
  5. jkuipers commented on Sep 23, 2022

    @jkuipers

    Note that this isn't quite correct:

    Any src/main/resources/META-INF/spring.factories file should move to META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports

    That spring.factories file can contain other entries besides autoconfiguration, so only when moving that entry would leave an empty file should you remove it: otherwise it should be left in place with just that entry removed.

  6. timtebeek commented on Sep 26, 2022

    @timtebeek
    MemberAuthor

    As discussed, this is already covered in Spring Boot Migrator. Might already resolve this issue here, unless we want to pull that up into Rewrite-Spring.

  7. self-assigned this
    on Nov 29, 2022
  8. moved this from Backlog to In Progress in OpenRewriteon Nov 29, 2022
  9. added a commit that references this issue on Dec 5, 2022
    c4e124d
  10. Repository owner moved this from In Progress to Done in OpenRewriteon Dec 5, 2022
  11. added this to the 4.31.0 milestone on Dec 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

boot-2.7recipe

Type

No type

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions