Spring Boot - 启动*

启动器

springboot项目会有很多spring-boot-starter打头的引用,这些引用是干什么用的,都有哪些,带着这些问题去官网看了一下官方文档,现将结果整理一下。

引用说明
spring-boot-starter核心启动器,包括自动配置支持,日志记录和YAML
spring-boot-starter-activemq 使用Apache ActiveMQ的消息队列
spring-boot-starter-amqp使用Spring AMQP和Rabbit MQ消息队列
spring-boot-starter-aop使用SpringAOP和AspectJ进行切面编程包
spring-boot-starter-artemis使用Apache Artemis的消息队列
spring-boot-starter-batch使用轻量级的大数据量的并行处理(批处理)框架SpringBatch
spring-boot-starter-cacheSpring缓存框架   
spring-boot-starter-cloud-connectorsSpring Cloud Connectors,云连接器,便于PaaS应用在各种平台上连接到后端像数据库和消息经纪服务
spring-boot-starter-data-cassandraNoSQL数据库cassandra
spring-boot-starter-data-cassandra-reactiveNoSQL数据库cassandra响应式编程
spring-boot-starter-data-couchbaseNoSQL数据库Couchbase
spring-boot-starter-data-couchbase-reactive NoSQL数据库Couchbase响应式编程
spring-boot-starter-data-elasticsearch使用Elasticsearch搜索和分析引擎
spring-boot-starter-data-jdbc使用jdbc连接数据库进行数据支持久化
spring-boot-starter-data-jpa使用jpa连接数据库进行数据支持久化
spring-boot-starter-data-ldap使用ldap目录服务
spring-boot-starter-data-mongodb使用NoSQL数据库mongodb
spring-boot-starter-data-mongodb-reactive使用NoSQL数据库mongodb响应式编程
spring-boot-starter-data-neo4j使用NoSQL数据库neo4j
spring-boot-starter-data-redis使用NoSQL数据库redis
spring-boot-starter-data-redis-reactive使用NoSQL数据库redis响应式编程
spring-boot-starter-data-restrest风格使用springData
spring-boot-starter-data-solr使用solr搜索和分析引擎
spring-boot-starter-freemarker使用FreeMarker视图构建MVC Web应用程序
spring-boot-starter-groovy-templates使用Groovy模板视图构建MVC Web应用程序
spring-boot-starter-hateoas使用SpringMVC和SpringHATEOAS构建基于超媒体的RESTful Web应用程序
spring-boot-starter-integration使用SpringIntegration,类似消息队列,用于企业集成的框架
spring-boot-starter-jdbc使用jdbc连接池
spring-boot-starter-jersey使用jersey构建基于超媒体的RESTful Web应用程序
spring-boot-starter-jooq使用jooq数据库ORM框架
spring-boot-starter-json支持json读写
spring-boot-starter-jta-atomikos使用atomikos解决分布式事务
spring-boot-starter-jta-bitronix使用bitronix解决分布式事务
spring-boot-starter-mail使用Java Mail发送邮件
spring-boot-starter-mustache使用mustache轻量级模板语言视图构建MVC Web应用程序
spring-boot-starter-oauth2-client使用oauth2授权框架客户端
spring-boot-starter-oauth2-resource-server使用oauth2授权框架服务端
spring-boot-starter-quartz使用quartz任务调度框架
spring-boot-starter-security使用security安全框架
spring-boot-starter-test使用单元测试包含JUnit、 Hamcrest和 Mockito
spring-boot-starter-thymeleaf使用thymeleaf模板语言视图构建MVC Web应用程序
spring-boot-starter-validation使用基于Hibernate Validator的类数据校验
spring-boot-starter-web构建网站开发,包括RESTful,Spring MVC,使用Tomcat作为默认嵌入容器
spring-boot-starter-web-services使用WebServices
spring-boot-starter-webflux使用WebFlux响应式编程,与springMVC功能类似
spring-boot-starter-websocket使用websocket通讯服务
spring-boot-starter-actuator使用actuator监控应用健康
spring-boot-starter-jetty使用jetty作为嵌入式容器
spring-boot-starter-log4j2使用log4j2记录日志
spring-boot-starter-logging使用logging记录日志 默认
spring-boot-starter-reactor-netty使用netty作为嵌入式容器
spring-boot-starter-tomcat使用tomcat作为嵌入式容器 默认
spring-boot-starter-undertow使用undertow

启动机制

Springboot 启动时主要做3件事:

1) 整合第三方依赖 => maven 加载依赖 (pom.xml)

2) 集成SpringMVC

3) 启动Tomcat

@SpringBootApplication = @SpringBootConfiguration + @ComponentScan + @EnableAutoConfiguration

@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@SpringBootConfiguration
@EnableAutoConfiguration
@ComponentScan(
    excludeFilters = {@Filter(
    type = FilterType.CUSTOM,
    classes = {TypeExcludeFilter.class}
), @Filter(
    type = FilterType.CUSTOM,
    classes = {AutoConfigurationExcludeFilter.class}
)}
)
public @interface SpringBootApplication {
    @AliasFor(
        annotation = EnableAutoConfiguration.class
    )
    Class<?>[] exclude() default {};

    @AliasFor(
        annotation = EnableAutoConfiguration.class
    )
    String[] excludeName() default {};

    @AliasFor(
        annotation = ComponentScan.class,
        attribute = "basePackages"
    )
    String[] scanBasePackages() default {};

    @AliasFor(
        annotation = ComponentScan.class,
        attribute = "basePackageClasses"
    )
    Class<?>[] scanBasePackageClasses() default {};
}

@SpringBootConfiguration

@SpringBootApplication is a @Configuration, which is a configuration class in Spring container.

@EnableAutoConfiguration

@EnableAutoConfiguration will import @EnableWebMvc to start tomcat.

org.springframework.boot.autocnfigure.web.servlet.WebMvcAutoConfiguraion

@Bean
@ConditionOnClass(name = "org.apache.catalina.startup.Tomcat") // 内嵌Tomcat
public TomcatServiceFactoryCustomizer tomcatServiceFactoryCustomizer (ServiceProperties serviceProperties) {
	return new TomcatServiceFactoryCustomizer (serviceProperties);
}
...

start tomcat

Spring Boot默认启动嵌入式tomcat容器,如果要改变启动jetty,需要去pom文件中配置。

@SprngBootApplication -> @SpringBootConfiguration -> @EnableAutoConfiguration -> @Import({AutoConfigurationImportSelector.class})

-> AutoConfigurationImportSelector (spring.factories)

-> [org.springframework.boot:spring-boot-autoconfigure:2.2.2RELEASE] - spring.factories

import org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryConfiguration.**EmbeddedTomcat**;

-> EmbeddedTomcat -> TomcatServletWebServerFactory(Spring管理)

-> WebServer (getWebServer)-> TomcatWebServer -> this.tomcat.start()
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值