创建自己的Spring Boot starter

本文深入解析Spring Boot Starter的工作原理,包括autoconfigure与starter模块的作用及其内部实现细节,并通过swagger-spring-boot-starter实例展示了如何配置与使用这些组件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Spring Boot starter 的组件

  • autoconfigure
  • starter

autoconfigure模块

包含自动配置的代码

starter模块

包含autoconfigure模块所依赖的包以及通用的包

命名

  • 不要以 spring-boot 开头
  • xxx-spring-boot-autoconfigure 及 xxx-spring-boot-starter
  • autoconfigure 和 starter 合在一起 xxx-spring-boot-starter
  • configuration key 不要和Spring Boot使用的冲突
  • 为了更好的支持IDE(properties文件中自动提示)需要在autoconfigure模块下提供META-INF/spring-configuration-metadata.json

swagger-spring-boot-starter 实例

  • swagger-spring-boot-starter
  • swaager-spring-boot-autoconfigure

swagger 配置提取

  • documentationType:[name:"",version:""]# 取值:swagger 1.2;swagger 2.0;spring-web 1.0
  • pathMapping # 映射的url
  • basePackage # 扫描的包
  • excludePath # 排除的url
  • title # 文档标题
  • description # 文档描述
  • version # 版本号
  • scheme # 安全模式:key,oauth
  • param.name # 参数名称
  • param.type # 参数传递位置
  • oauth2.clientId # oauth2模式的 clientId
  • oauth2.secretId # oauth2模式的 secretId
  • oauth2.realm # oauth2模式的 secretId
  • oauth2.scope # oauth2模式的 scope
  • oauth2.scope.name # oauth2模式的 scope 名称
  • oauth2.scope.description # oauth2模式的 scope描述
  • oauth2.grantType #授权类型
  • oauth2.grantType.name # 授权类型,取值:authorization_code、client_credentials、password
  • oauth2.grantType.tokenUrl # 获取token的 URL
  • oauth2.grantType.authorizeUrl #认证URL

代码swagger-spring-boot

参考

mybatis-spring-boot-starter

转载于:https://my.oschina.net/jast90/blog/1555923

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值