1

If you are a Spring Boot user, you must have such a development experience. When we want to introduce a certain function, we only need to directly introduce the corresponding Starter in the maven or gradle configuration, and it can be used immediately without the need for Write an xml or java configuration class to initialize various beans like traditional Spring applications.

If you have explored the principles of these Starters, then you must know that Spring Boot does not eliminate these beans that you want to configure, but makes these beans into some default configuration classes, and uses /META-INF/spring.factories This file to specify the default configuration to load.

In this way, when the Spring Boot application starts, the beans will be loaded according to the configuration class specified in the /META-INF/spring.factories file in the various Starters introduced.

In Spring Boot 2.7, which was just released this time, there is a deprecated content about this /META-INF/spring.factories file, so for developers with custom Starters, they have time to hurry up The change has changed since support for /META-INF/spring.factories will be removed starting in Spring Boot 3.

So how to change it? Let's take a swagger starter we wrote before as an example. Its content /META-INF/spring.factories is as follows:

 org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
  com.spring4all.swagger.SwaggerAutoConfiguration

We only need to create a new file: /META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports , the content only needs to put the configuration class directly, for example:

 com.spring4all.swagger.SwaggerAutoConfiguration

Note: There is one more spring directory here.

If you think it is too troublesome to maintain, you can also use mica-auto to automatically generate it. For details, see this article posted earlier.

If you encounter difficulties in the learning process? You can join our high-quality Spring technical exchange group , participate in exchanges and discussions, and learn and progress better! More Spring Boot tutorials can be clicked directly! , welcome to collect and forward support!

Welcome to my public account: Programmer DD. Learn about cutting-edge industry news for the first time, share in-depth technical dry goods, and obtain high-quality learning resources

程序猿DD
2.2k 声望2.8k 粉丝

作品:《Spring Cloud微服务实战》、SpringForAll社区、OpenWrite、Youtube中文配音