Skip to content

2.7 Changes to Auto-Configuration #197

@timtebeek

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.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions