Spring Boot启动器

2023-05-16

文章目录

    • Spring Boot启动器简介
    • 自定义springboot启动器
      • 命名规约
      • 自定义starter步骤
        • 1. 创建一个Spring boot项目
        • 2. 导入pom
        • 3. 编写配置类
        • 4. 在resources/META-INF目录下新建spring.factories文件
        • 5. mvn install到本地仓库
        • 6. 使用自定义starter
      • Spring Boot提供的启动器(starter)

Spring Boot启动器简介

Springboot包含许多启动项目并快速运行所需的依赖项,并且具有一组受支持的被管理的传递性依赖项,所有的正式starter都遵循类似的命名模式spring-boot-starter-*

starter启动器是一组方便的依赖项描述符,可以在pom中引入其依赖,免去了自己需要引用很多依赖类,并且SpringBoot会自动进行类的自动配置。例如,如果要使用SpringMVC开发web应用,可以在pom文件中包含spring-boot-starter-web依赖项,如下:

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>

自定义springboot启动器

有时候,springboot官方提供的场景启动器(starter)并不能很好的满足我们的需求,这时候,我们可以考虑自行编写场景启动器,然后在common模块引入即可。

启动器包了一层自动配置类,自动配置类作用就是写@Bean注解,往容器里面配置Bean,然后Bean所需要的属性都来源于配置文件所映射的属性配置类。

springboot是按照这个模式开发启动器的,所以我们也这样操作,在需要的项目中引入启动器即可。

命名规约

  • spring官方:spring-boot-starter-xxx

  • 自定义:xxx-spring–boot-starter

自定义starter步骤

1. 创建一个Spring boot项目

在这里插入图片描述

在这里插入图片描述

2. 导入pom

        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.2.0</version>
        </dependency>

3. 编写配置类

然后新建一个配置类

package com.aliencat.springboot.starter.config;

import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * mybatis plus分页插件配置
 * @author wj
 */
@ConditionalOnClass(value = {PaginationInterceptor.class})
@EnableTransactionManagement
@Configuration
public class MybatisPlusConfig {
    @Bean
    public PaginationInterceptor paginationInterceptor(){
        return new PaginationInterceptor();
    }
}

4. 在resources/META-INF目录下新建spring.factories文件

在这里插入图片描述

spring.factories:

# Auto Configure
org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.aliencat.springboot.starter.config.MybatisPlusConfig

5. mvn install到本地仓库

在这里插入图片描述

在这里插入图片描述

6. 使用自定义starter

构建成功后,我们就可以再其他springboot项目的pom中引入自定义starter:

        <dependency>
            <groupId>com.aliencat.springboot.starter</groupId>
            <artifactId>mystarter</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>

Spring Boot提供的启动器(starter)

如下所示:

名称描述pom
spring-boot-starter核心Starter工具,包括自动配置支持,日志记录和YAMLpom
spring-boot-starter-activemq使用Apache ActiveMQ的JMS消息传递Starterpom
spring-boot-starter-amqp使用Spring AMQP和Rabbit MQ的Starterpom
spring-boot-starter-aop使用Spring AOP和AspectJ进行面向方面编程的Starterpom
spring-boot-starter-artemis使用Apache Artemis的JMS消息传递Starterpom
spring-boot-starter-batch使用Spring Batch的Starterpom
spring-boot-starter-cache使用Spring Framework的缓存支持的Starterpom
spring-boot-starter-cloud-connectors使用Spring Cloud Connectors的Starter程序,可简化与Cloud Foundry和Heroku等云平台中服务的连接。不推荐使用Java CFEnvpom
spring-boot-starter-data-cassandra使用Cassandra分布式数据库和Spring Data Cassandra的Starterpom
spring-boot-starter-data-cassandra-reactive使用Cassandra分布式数据库和Spring Data Cassandra Reactive的Starterpom
spring-boot-starter-data-couchbase使用Couchbase面向文档的数据库和Spring Data Couchbase的Starterpom
spring-boot-starter-data-couchbase-reactive使用Couchbase面向文档的数据库和Spring Data Couchbase Reactive的Starterpom
spring-boot-starter-data-elasticsearch使用Elasticsearch搜索和分析引擎以及Spring Data Elasticsearch的Starterpom
spring-boot-starter-data-jdbc使用Spring Data JDBC的Starterpom
spring-boot-starter-data-jpa将Spring Data JPA与Hibernate结合使用的Starterpom
spring-boot-starter-data-ldap使用Spring Data LDAP的Starterpom
spring-boot-starter-data-mongodb使用MongoDB面向文档的数据库和Spring Data MongoDB的Starterpom
spring-boot-starter-data-mongodb-reactive使用MongoDB面向文档的数据库和Spring Data MongoDB Reactive的Starterpom
spring-boot-starter-data-neo4j使用Neo4j图形数据库和Spring Data Neo4j的Starter工具pom
spring-boot-starter-data-redis使用Redis键值数据存储与Spring Data Redis和Lettuce客户端的Starterpom
spring-boot-starter-data-redis-reactive将Redis键值数据存储与Spring Data Redis Reacting和Lettuce客户端一起使用的Starterpom
spring-boot-starter-data-rest使用Spring Data REST在REST上公开Spring数据存储库的Starterpom
spring-boot-starter-data-solr将Apache Solr搜索平台与Spring Data Solr结合使用的Starterpom
spring-boot-starter-freemarker使用FreeMarker视图构建MVC Web应用程序的Starterpom
spring-boot-starter-groovy-templates使用Groovy模板视图构建MVC Web应用程序的Starterpom
spring-boot-starter-hateoas使用Spring MVC和Spring HATEOAS构建基于超媒体的RESTful Web应用程序的Starterpom
spring-boot-starter-integration使用Spring Integration的Starterpom
spring-boot-starter-jdbc结合使用JDBC和HikariCP连接池的Starterpom
spring-boot-starter-jersey使用JAX-RS和Jersey构建RESTful Web应用程序的Starter的替代品spring-boot-starter-webpom
spring-boot-starter-jooq使用jOOQ访问SQL数据库的Starter。替代spring-boot-starter-data-jpaspring-boot-starter-jdbcpom
spring-boot-starter-json读写JSONStarterpom
spring-boot-starter-jta-atomikos使用Atomikos的JTA交易Starterpom
spring-boot-starter-jta-bitronix使用Bitronix的JTA交易Starterpom
spring-boot-starter-mail使用Java Mail和Spring Framework的电子邮件发送支持的Starterpom
spring-boot-starter-mustache使用Mustache视图构建Web应用程序的Starterpom
spring-boot-starter-oauth2-client使用Spring Security的OAuth2 / OpenID Connect客户端功能的Starterpom
spring-boot-starter-oauth2-resource-server使用Spring Security的OAuth2资源服务器功能的Starterpom
spring-boot-starter-quartzStarter使用Quartz Schedulerpom
spring-boot-starter-rsocket用于构建RSocket客户端和服务器的Starter程序。pom
spring-boot-starter-security使用Spring Security的Starterpom
spring-boot-starter-test用于使用包括JUnit,Hamcrest和Mockito在内的库测试Spring Boot应用程序的Starter程序pom
spring-boot-starter-thymeleaf使用Thymeleaf视图构建MVC Web应用程序的Starterpom
spring-boot-starter-validation初学者,可将Java Bean验证与Hibernate Validator结合使用pom
spring-boot-starter-web使用Spring MVC构建Web(包括RESTful)应用程序的Starter程序。使用Tomcat作为默认的嵌入式容器pom
spring-boot-starter-web-services使用Spring Web Services的Starterpom
spring-boot-starter-webflux使用Spring Framework的反应式Web支持构建WebFlux应用程序的Starterpom
spring-boot-starter-websocket使用Spring Framework的WebSocket支持构建WebSocket应用程序的Starterpom
spring-boot-starter-actuator使用Spring Boot的Actuator的Starter程序,该启动器提供了生产就绪功能,可帮助您监视和管理应用程序pom
spring-boot-starter-jetty使用Jetty作为嵌入式servlet容器的Starter的替代品spring-boot-starter-tomcatpom
spring-boot-starter-log4j2使用Log4j2进行日志记录的启动器的替代品spring-boot-starter-loggingpom
spring-boot-starter-logging使用Logback进行日志记录的启动器。默认记录启动器pom
spring-boot-starter-reactor-nettyStarter用于将Reactor Netty用作嵌入式反应式HTTP服务器。pom
spring-boot-starter-tomcatStarter用于将Tomcat用作嵌入式servlet容器。默认使用的servlet容器启动器spring-boot-starter-webpom
spring-boot-starter-undertow使用Undertow作为嵌入式servlet容器的Starter的替代品spring-boot-starter-tomcatpom
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Spring Boot启动器 的相关文章

  • python编写程序统计一元人民币换成一分、两分和五分的所有兑换方案个数(用while循环)

    a 61 int input 34 输入钱数 xff08 单位 xff1a 元 xff09 34 e 61 a 100 count 61 0 i 61 1 while i lt e 5 43 1 i 43 61 1 b 61 e 5 i 2
  • springboot简易整合mybatis

    SpringBoot整合Mybatis篇 实现单表mybatis整合 准备sql 创建数据库 create database if not exists 96 mybatis 96 修改数据库默认字节编码 alter database 96
  • Springboot+PageHelper实现分页(前后端简单展示)

    Springboot 43 PageHelper实现分页 前后端简单展示 创建表及赋值 创建表 DROP TABLE IF EXISTS 96 page learn 96 CREATE TABLE 96 page learn 96 96 i
  • SpringBoot缓存注解使用(无数据库操作)

    SpringBoot缓存注解使用 无数据库操作 缓存注解介绍 64 EnableCaching注解 xff1a 开启注解缓存的支持 64 Cacheable注解 xff1a 对方法的查询结果进行缓存 64 CachePut注解 xff1a
  • JavaScript(基于Java开发的学习)

    JavaScript 基于Java基础学习 JavaScript结构图 1 JS简介 JavaScript xff08 行为 xff09 xff1a 是一种弱类型脚本语言 xff0c 其源码不需经过编译 xff0c 而是由浏览器解释运行 x
  • MyBatis框架

    MyBatis学习结构 1 MyBatis框架简介 MyBatis是一款优秀的持久层框架 它支持定制化SQL 存储过程以及高级映射 MyBatis避免了几乎所有的JDBC代码和手动设置参数以及获取结果集 MyBatis可以使用简单的XML或
  • springboot+vue实现增删改查小demo

    学习vue xff0c 就想着自己搭建一个框架学习一下 xff0c 本文属于vue与后台的增删改查入门demo xff0c 不做讲解 xff0c 只为了记录一下代码 后台框架前台框架的搭建自己百度就可以做到了 项目的源码地址 https g
  • JWT(Json web token)

    1 什么是JWT 官网地址 JSON Web Token Introduction jwt io 翻译 jsonwebtoken xff08 JWT xff09 是一个开放标准 xff08 rfc7519 xff09 xff0c 它定义了一
  • MyBatis-plus

    MyBatis plus学习结构图 1 MyBatis plus简介 为什么要学习它呢 MyBatisPlus可以节省我们大量工作时间 xff0c 所有的CRUD代码它都可以自动化完成 JPA tk mapper MyBatisPlus 偷
  • QT制作简易串口

    QT 实现一个简易版串口调试助手 文章目录 1 设计 UI 界面 2 具体代码编写 3 最终实现效果图 一 设计 UI 界面 设计 UI 界面之前 xff0c 让我们先看一下别人设计的串口助手大概长什么样子 xff0c 具体有哪些功能 我们
  • MVC的执行流程

    MVC的执行流程 1 执行服务器2 发送请求到tomcat3 响应客户端总结 1 执行服务器 根据配置创建DispatcherServlet对象 这个对象已创建 xff0c 会根据contextConfigLocation的配置查找spri
  • KVM 虚拟化

    kvm虚拟化 Kvm的安装 KVM下的虚拟机安装和相互访问约束 推荐下载TightVNC 也可以使用 VNCSever 一 虚拟化产品介绍 linux类的虚拟化软件 qemu xff0c 软件纯模拟全虚拟化软件 xff0c 特别慢 xen
  • Linux服务器连接失败,针对ping不通和无法上网问题 CentOS 7

    1 防火墙是否关闭 防火墙关闭命令 xff1a systemctl stop firewalld service 关闭 systemctl start firewalld service 重启防火墙 systemctl disable fi
  • 数据挖掘Java——KNN算法的实现

    一 KNN算法的前置知识 k 近邻 xff08 kNN k NearestNeighbor xff09 是在训练集中选取离输入的数据点最近的k个邻居 xff0c 根据这个k个邻居中出现次数最多的类别 xff08 最大表决规则 xff09 x
  • 数据挖掘Java——DBSCAN算法的实现

    一 DBSCAN算法的前置知识 DBSCAN算法 xff1a 如果一个点q的区域内包含多于MinPts个对象 xff0c 则创建一个q作为核心对象的簇 然后 xff0c 反复地寻找从这些核心对象直接密度可达的对象 xff0c 把一些密度可达
  • 数据挖掘Java——Kmeans算法的实现

    一 K means算法的前置知识 k means算法 xff0c 也被称为k 平均或k 均值 xff0c 是一种得到最广泛使用的聚类算法 相似度的计算根据一个簇中对象的平均值来进行 算法首先随机地选择k个对象 xff0c 每个对象初始地代表
  • Git Bash中怎么复制与粘贴

    git里面的复制粘贴 一 第一种键盘复制粘贴 右击 xff0c 把git bash应用的Options 配置项打开 复制 ctrl 43 insert 粘贴 shift 43 insert 二 第二种鼠标复制粘贴 1 选中你要复制的部分 x
  • 最新版 springboot集成kafka

    在上一篇文章中介绍了怎么在mac系统上搭建kafka xff0c 既然搭建成功了 xff0c 肯定要集成到项目中使用啊 xff0c 但是怎么集成呢 xff0c 这里把我本人集成的代码以及怎么一步步集成的放上来 xff0c 源码也会在本文的后
  • Python循环输出1~100,每10个换一行

    for i in range 1 101 print i end 61 34 34 if i 10 61 61 0 print
  • JavaScript中matches和match方法

    matches 主要是用来判断当前DOW节点是否能完全匹配对应的CSS选择器 xff0c 如果匹配成功 xff0c 返回true xff0c 反之则返回false 语法如下 xff1a element mathces seletor 这个方

随机推荐

  • Row size too large (> 8126). Changing some columns to TEXT or BLOB… | Mysql / MariaDB

    Row size too large gt 8126 Changing some columns to TEXT or BLOB Mysql MariaDB 我们最近将客户网站迁移到新服务器 xff0c 并在尝试导入其数据库时遇到以下错误
  • 一文教你完美解决Linux中Unable to locate package xxx问题,解决不了你打我!

    项目场景 xff1a 使用Ubuntu系统进行开发 问题描述 这两天跟着一门网 课学 把html的网页部署到云服务器 xff0c 于是租了个Ubuntu云服务器 xff0c 照着网课的代码去执行 xff0c 然后一直出现这个问题 xff0c
  • Spring相关知识点(全集)

    1Spring概述 1 1Spring概述 1 spring是一个开源框架 2 spring为简化企业级开发而生 xff0c 使用spring xff0c Javabean就可以实现很多以前要考EJB才能实现的功能 同样的功能 xff0c
  • 云服务的三种模式

    1 laaS 基础设施即服务 laaS xff08 Infrastructure as a Service xff09 即基础设施即服务 提供给消费者的服务是对所有计算基础设施的利用 xff0c 包括处理CPU 内存 存储 网络和其他基本的
  • Caused by: java.lang.IllegalStateException: No application config found or it‘s not a valid config!

    复习springboot时遇到的问题 xff0c 找不到application properties 配置文件 xff0c 很奇怪 xff0c 明明放到resource下面了 xff0c 就是编译不进去 xff0c 运行后target根本没
  • Win系统远程桌面连接教程/查询用户名和密码

    要连接的电脑命名为A 被连接的电脑命名为B B电脑 xff1a 右键电脑属性 点击远程设置 点击允许远程连接此电脑 win 43 r打开cmd输入ipconfig查询ip地址 不知道用户名和密码的 输入net user查询用户名 xff0c
  • Tomcat 9.0安装及配置

    目录 一 获取安装包 二 Tomcat9 0 67 环境配置 三 验证 四 补充 一 获取安装包 官网下载https tomcat apache org 解压至英文文件夹下 xff08 路径中需要全英文 xff09 xff0c 记住路径 百
  • 1.Matlab图像的读取和显示

    在开始之前 xff0c 我们需要在脚本里创建个 m文件 xff0c 然后运行 每次运行时要更换至脚本的路径 clc clear closeall 在一个文件的开头经常会看到 那么他们的作用是什么呢 xff1f clc span class
  • 分享一个word转pdf的工具类Aspose[java]

    项目中使用到office文件的格式转换pdf阅读 xff0c 但是没有一款好用的转换工具 由于本人是mac系统 xff0c openoffice也没法使用 xff0c 前期使用itext转换一直中文乱码 xff0c 也没有解决这个问题 xf
  • Window Sever 2012 密码忘记,修改密码的方法

    在VMWare中安装Window Server 2012忘记密码后如何进行破译修复 xff1f 方法如下 xff1a 进入BIOS 设置界面 xff0c 华硕是按f2 xff08 可以查询一下自己相应电脑进入BIOS界面的按键 xff09
  • UNIX环境高级编程笔记

    UNIX环境编程 一 UNIX基础知识1 1 Linux 主要特性1 2 Linux 内核1 3 Linux 目录结构1 4 登录1 登录名2 shell 1 5 输入和输出1 文件描述符2 标准输入 标准输出 标准错误3 不带缓冲的IO4
  • 实现map有序输出

    我们知道golang里的map是无序的 xff0c 不像python里的字典还可以对键值对顺序反序啥的 所以我们下面手动实现map的有序输出 xff0c 其实原理很简单 xff01 package main import 34 fmt 34
  • 三大框架-Spring

    一 概述 spring框架是以一个分层架构 有七个定义良好的模块组成 Spring模块构建在核心容器之上 核心容器定义了创建 配置和管理bean方式 1 Spring Core 核心容器 提供Spring的基本功能 2 SPring Con
  • Java——泛型和Io流

    目录 1 泛型 2 File对象 3 IO流 4 字节输入和输出流 5 缓存流 6 对象流 1泛型 1 1什么是泛型 1 泛型就是限制我们得数据类型 2 为什么使用泛型 我们原来在定义集合时 xff0c 是如下得定义方式 xff1a Lis
  • Spring框架入门学习笔记

    Spring概述 目录 Spring概述 IOC容器 概念 底层原理 Spring提供IOC容器实现两种方式 基于xml方式实现属性注入和对象创建 属性注入 xml注入集合属性 Spring中的bean类型 bean的作用域 bean的生命
  • &和&&的区别?

    amp 和 amp amp 都是Java中的逻辑运算符 xff0c 用于对两个布尔值进行逻辑运算 xff0c 但它们有着不同的特点和使用场景 xff0c 具体区别如下 xff1a 1 运算规则 amp 是按位与运算符 xff0c 它会对两个
  • MAC电脑GOland2022.2.1版本DEBUG问题

    在使用goland使用debug调试代码出现 API server listening at 127 0 0 1 56871 could not launch process debugserver or lldb server not f
  • Maven连接数据库

    1 创建一个maven项目 2 在resources中创建db properties配置文件和log4j properties日志的配置文件 db username 61 root db password 61 root db url 61
  • 关于vs2019网络问题解决方案

    首先将IPV4 的DNS设置为默认的114 114 114 114 xff0c 备用DNS为8 8 8 8 xff0c 若没有用 xff0c 则不勾选IPV6 xff0c 亲测有效 这个问题曾经也困扰了我好几个月 xff0c 甚至都想换掉v
  • Spring Boot启动器

    文章目录 Spring Boot启动器简介自定义springboot启动器命名规约自定义starter步骤1 创建一个Spring boot项目2 导入pom3 编写配置类4 在resources META INF目录下新建spring f