Spring Boot启动器

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
  • 3
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值