自定义 spring-boot-starter

自定义 spring-boot-starter
  • springboot规定一般官网的包名为 spring-boot-start-xxx (spring-boot-start-web)
  • 个人或者第三方命名规则为:xxx-spring-boot-start (pagehelper-spring-boot-start)
仿照 pageHelper创建 springboot包

当前为可引入jar包,我们创建maven创建项目; springboot 项目默认打包jar为 可执行文件,如果要更改成 可引入jar包,则需要更改为

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <classifier>exec</classifier>
    </configuration>
</plugin>

详细内容不多解释自行查看

普通的包结构信息
//pageHelper 引入包结构为
- 
    |- pagehlper.jar
    |- pagehelper-spring-boot-autoconfigure.jar
    |- pagehelper-spring-boot-starter.jar
    

//自定义包结构为
- white-spring-boot
    |- white-spring-boot-autoconfigure 自动配置类
    |- white-spring-boot-starter 加载类
    |- white-core 核心逻辑
white-spring-boot-starter

当前为空项目,主要内容新增文件 resources/META-INF/spring.provides

pageHelper 中引用的是如下,

provides: pagehelper-spring-boot-autoconfigure,pagehelper,mybatis-spring-boot-autoconfigure,mybatis,mybatis-spring

仿照写

white-spring-boot-starter 中引用的是

provides: white-core, white-spring-boot-autoconfigure
white-spring-boot-autoconfigure

仿照pagehelper-spring-boot-autoconfigure

创建启动加载文件 resources/META-INF/spring.factories

org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.apple.WhiteAutoConfiguration

创建com.apple.WhiteAutoConfiguration

@Configuration
@EnableConfigurationProperties(WhiteProperties.class)
public class WhiteAutoConfiguration {
    
}

@ConfigurationProperties(prefix = "white")
@Getter
@Setter
public class WhiteProperties {

    private Properties properties = new Properties();

    public Properties getProperties() {
        return this.properties;
    }

    private String userName;

    private Integer age;
}

源码 github

转载于:https://my.oschina.net/u/1459447/blog/3079663

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值