当前位置:   article > 正文

Spring Boot开发自定义的starter_自己创建springbootstarter如何给包命名

自己创建springbootstarter如何给包命名

目录

一、Spring Boot的starter概述

二、自定义starter的命名规则

三、自定义starter实战

1. 创建spring工程

 2. 修改pom.xml

 3. 编写配置类

4. 安装到本地maven仓库

5. 在其他项目中引入

6. 测试


一、Spring Boot的starter概述

        SpringBoot中的starter是一种非常重要的机制,能够抛弃以前繁杂的配置,将其统一集成进starter,应用者只需要在maven中引入starter依赖,SpringBoot就能自动扫描到要加载的信息并启动相应的默认配置。starter让我们摆脱了各种依赖库的处理,需要配置各种信息的困扰。SpringBoot会自动通过classpath路径下的类发现需要的Bean,并注册进IOC容器。SpringBoot提供了针对日常企业应用研发各种场景的spring-boot-starter依赖模块。所有这些依赖模块都遵循着约定成俗的默认配置,并允许我们调整这些配置,即遵循“约定大于配置”的理念。

二、自定义starter的命名规则

官方:spring-boot-starter-xxx

自定义:xxx-spring-boot-starter 

三、自定义starter实战

这里我们编写一个发送http请求的starter

1. 创建spring工程

根据需要引入依赖,Spring Configuration Processor 可以自动生成配置时的代码提示

 

 2. 修改pom.xml

创建spring工程后,可以在pom文件里看到当前项目的 GAV

 然后删除 bulid 模块

引入 hutool 依赖,使用hutool的 Http客户端工具类来发送http请求。

官网地址:https://www.wpsshop.cn/w/羊村懒王/article/detail/466150

推荐阅读
相关标签
  

闽ICP备14008679号