编写自己的 starter
说了那么多,终于到了实操环节,通过上面的介绍,我们可以大致得出编写自己的 starter
步骤。
1. 创建名字为 xxx-spring-boot-starter
的启动器项目。
2. 创建名字为 xxx-spring-boot-autoconfigure的项目。
- 编写属性绑定类
xxxProperties
. - 编写服务类,引入
xxxProperties
. - 编写自动配置类
XXXAutoConfiguration
注入配置。 - 创建
spring.factories
文件,用于指定要自动配置的类。
3. 启动器项目为空项目,用来引入 xxx-spring-boot-autoconfigure
等其他依赖。
4. 项目引入 starter
,配置需要配置的信息。
发表回复