SpringBoot-自定义Starter

步骤

创建xxxAutoConfiguration类
添加@Configuration注解修饰
添加@Conditionalxxx注解做注入条件判断
添加@AutoConfigureOrder注解注入顺序
添加@AutoConfigureAfter注解注入后操作

创建xxxProperties配置类
添加@ConfigurationProperties注解映射相关配置

xxxAutoConfiguration类添加@EnableConfigurationProperties注入配置类

参考WebMvcAutoConfiguration等自动注入类

模式

xxx-spring-boot-starter只用来做依赖导入(POM项目)
xxx-spring-boot-autoconfigure核心应用项目
第三方只需引入xxx-spring-boot-starter依赖即可

参考mybatis-spring-boot-starter

  

  

猜你喜欢

转载自www.cnblogs.com/BINGJJFLY/p/12040453.html