Spring Boot’s spring.factories Is Deprecated – Switch to AutoConfiguration.imports

Spring Boot 2.7 marks the spring.factories auto‑configuration loading method as deprecated, and Spring Boot 3 will remove it entirely, prompting developers to adopt the new AutoConfiguration.imports mechanism, which supports configuration slicing, custom SPI extensions, and more elegant handling via tools like mica‑auto.

Java Architecture Diary
Java Architecture Diary
Java Architecture Diary
Spring Boot’s spring.factories Is Deprecated – Switch to AutoConfiguration.imports

Official deprecation notice: Spring Boot 2.7 has marked the spring.factories auto‑configuration loading method as deprecated, and Spring Boot 3 will completely remove it, meaning existing spring‑boot‑starters will not be compatible.

1. What is spring.factories

Spring provides a mechanism similar to Java SPI that lists implementation class names in META-INF/spring.factories, which Spring Boot starters use to load custom auto‑configuration classes.

This custom SPI is the foundation of Spring Boot starter implementations: when you depend on a starter, it supplies the relevant classes for loading; without the starter, those classes are not loaded.

2. New feature: support for configuration slicing

2.1 Why support configuration slicing

Using mybatis-plus-boot-starter as an example, many spring config beans are listed in spring.factories, making maintenance difficult for developers.

Environment configuration processor

Auto‑configuration classes

2.2 How to use the auto‑configuration slicing feature

Create an

org.springframework.boot.autoconfigure.AutoConfiguration.imports

file:

├── src
│   └── main
│       └── resources
│           ├── META-INF
│           │   └── spring
│           │       └── org.springframework.boot.autoconfigure.AutoConfiguration.imports

2.3 Source analysis of configuration slicing

Compatible with the original spring.factories loading method

Read slice configuration and load related classes

3. Extending your own Import SPI

pig [1] defines org.springframework.cloud.openfeign.FeignClient.imports to inject FeignClient via SPI, avoiding loading issues caused by irregular package rules.

Use

ImportCandidates.load()

4. A more elegant way to handle configuration slicing with mica‑auto

If you find managing SPI files cumbersome, try mica‑auto [2]. The latest version can generate and configure the imports file automatically using the @AutoConfiguration annotation.

imports file

References

[1] pig: https://github.com/pig-mesh/pig

[2] mica-auto: https://github.com/lets-mica/mica-auto

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaSpring BootSpring Factoriesconfiguration slicingauto-configuration
Java Architecture Diary
Written by

Java Architecture Diary

Committed to sharing original, high‑quality technical articles; no fluff or promotional content.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.