温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

怎么进行自定义spring-boot-starter

发布时间:2021-10-19 10:46:53 来源:亿速云 阅读:88 作者:柒染 栏目:大数据

这期内容当中小编将会给大家带来有关怎么进行自定义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

上述就是小编为大家分享的怎么进行自定义spring-boot-starter了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注亿速云行业资讯频道。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI