java框架之SpringBoot(10)-启动流程及自定义starter
启动流程
直接从 SpringBoot 程序入口的 run 方法看起:
public static ConfigurableApplicationContext run(Object source, String... args) {
return run(new Object[] { source }, args);
}
org.springframework.boot.SpringApplication#run(java.lang.Object, java.lang.String...)
执行第 2 行的 run(new Object[] { source }, args) 方法:
public static ConfigurableApplicationContext run(Object[] sources, String[] args) {
return new SpringApplication(sources).run(args);
}
org.springframework.boot.SpringApplication#run(java.lang.Object[], java.lang.String[])
可以看到,这里启动实际上是分为两步,先是创建 SpringApplication 对象,然后执行该对象的 run 方法。下面根据这两步进行深入:
创建SpringApplication对象
下一步会进入 SpringApplication 类的构造方法:
public SpringApplication(Object... sources) {
initialize(sources);
}
org.springframework.boot.SpringApplication#SpringApplication(java.lang.Object...)
接着进入 initialize 方法:
private void initialize(Object[] sources) {
if (sources != null && sources.length > 0) {
// 保存配置类,包含入口类
this.sources.addAll(Arrays.asList(sources));
}
// 判断当前是否是一个 web 应用
this.webEnvironment = deduceWebEnvironment();
// 从类路径下找到 META-INF/spring.factories 配置的所有 ApplicationContextInitializer 类并反射创建实例并保存到当前 SpringApplication 实例的 initializers 属性
setInitializers((Collection) getSpringFactoriesInstances(ApplicationContextInitializer.class));
// 从类路径下找到 META-INF/spring.factories 配置的所有 ApplicationListener 类并反射创建实例保存到当前 SpringApplication 实例的 listeners 属性
setListeners((Collection) getSpringFactoriesInstances(ApplicationListener.class));
// 从调用栈中获取到执行了 main 方法的配置类即入口类保存到当前 SpringApplication 实例的 mainApplicationClass 属性
this.mainApplicationClass = deduceMainApplicationClass();
}
org.springframework.boot.SpringApplication#initialize
在创建 SpringApplication 对象的过程中实例化了类路径下 META-INF/spring.factories 中 ApplicationContextInitializer 节对应的应用上下文初始化器类和 ApplicationListener 节对应的应用监听器类并保存到了 SpringApplication 对象中。

可以看到在很多包中都有这个文件,下面为自动配置包中的 spring.factories 文件:
# Initializers org.springframework.context.ApplicationContextInitializer=\ org.springframework.boot.autoconfigure.SharedMetadataReaderFactoryContextInitializer,\ org.springframework.boot.autoconfigure.logging.AutoConfigurationReportLoggingInitializer # Application Listeners org.springframework.context.ApplicationListener=\ org.springframework.boot.autoconfigure.BackgroundPreinitializer # Auto Configuration Import Listeners org.springframework.boot.autoconfigure.AutoConfigurationImportListener=\ org.springframework.boot.autoconfigure.condition.ConditionEvaluationReportAutoConfigurationImportListener # Auto Configuration Import Filters org.springframework.boot.autoconfigure.AutoConfigurationImportFilter=\ org.springframework.boot.autoconfigure.condition.OnClassCondition # Auto Configure org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ org.springframework.boot.autoconfigure.admin.SpringApplicationAdminJmxAutoConfiguration,\ org.springframework.boot.autoconfigure.aop.AopAutoConfiguration,\ org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration,\ org.springframework.boot.autoconfigure.batch.BatchAutoConfiguration,\ org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration,\ org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration,\ org.springframework.boot.autoconfigure.cloud.CloudAutoConfiguration,\ org.springframework.boot.autoconfigure.context.ConfigurationPropertiesAutoConfiguration,\ org.springframework.boot.autoconfigure.context.MessageSourceAutoConfiguration,\ org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration,\ org.springframework.boot.autoconfigure.couchbase.CouchbaseAutoConfiguration,\ org.springframework.boot.autoconfigure.dao.PersistenceExceptionTranslationAutoConfiguration,\ org.springframework.boot.autoconfigure.data.cassandra.CassandraDataAutoConfiguration,\ org.springframework.boot.autoconfigure.data.cassandra.CassandraRepositoriesAutoConfiguration,\ org.springframework.boot.autoconfigure.data.couchbase.CouchbaseDataAutoConfiguration,\ org.springframework.boot.autoconfigure.data.couchbase.CouchbaseRepositoriesAutoConfiguration,\ org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchAutoConfiguration,\ org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchDataAutoConfiguration,\ org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchRepositoriesAutoConfiguration,\ org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration,\ org.springframework.boot.autoconfigure.data.ldap.LdapDataAutoConfiguration,\ org.springframework.boot.autoconfigure.data.ldap.LdapRepositoriesAutoConfiguration,\ org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration,\ org.springframework.boot.autoconfigure.data.mongo.MongoRepositoriesAutoConfiguration,\ org.springframework.boot.autoconfigure.data.neo4j.Neo4jDataAutoConfiguration,\ org.springframework.boot.autoconfigure.data.neo4j.Neo4jRepositoriesAutoConfiguration,\ org.springframework.boot.autoconfigure.data.solr.SolrRepositoriesAutoConfiguration,\ org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration,\ org.springframework.boot.autoconfigure.data.redis.RedisRepositoriesAutoConfiguration,\ org.springframework.boot.autoconfigure.data.rest.RepositoryRestMvcAutoConfiguration,\ org.springframework.boot.autoconfigure.data.web.SpringDataWebAutoConfiguration,\ org.springframework.boot.autoconfigure.elasticsearch.jest.JestAutoConfiguration,\ org.springframework.boot.autoconfigure.freemarker.FreeMarkerAutoConfiguration,\ org.springframework.boot.autoconfigure.gson.GsonAutoConfiguration,\ org.springframework.boot.autoconfigure.h2.H2ConsoleAutoConfiguration,\ org.springframework.boot.autoconfigure.hateoas.HypermediaAutoConfiguration,\ org.springframework.boot.autoconfigure.hazelcast.HazelcastAutoConfiguration,\ org.springframework.boot.autoconfigure.hazelcast.HazelcastJpaDependencyAutoConfiguration,\ org.springframework.boot.autoconfigure.info.ProjectInfoAutoConfiguration,\ org.springframework.boot.autoconfigure.integration.IntegrationAutoConfiguration,\ org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration,\ org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,\ org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration,\ org.springframework.boot.autoconfigure.jdbc.JndiDataSourceAutoConfiguration,\ org.springframework.boot.autoconfigure.jdbc.XADataSourceAutoConfiguration,\ org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration,\ org.springframework.boot.autoconfigure.jms.JmsAutoConfiguration,\ org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration,\ org.springframework.boot.autoconfigure.jms.JndiConnectionFactoryAutoConfiguration,\ org.springframework.boot.autoconfigure.jms.activemq.ActiveMQAutoConfiguration,\ org.springframework.boot.autoconfigure.jms.artemis.ArtemisAutoConfiguration,\ org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration,\ org.springframework.boot.autoconfigure.groovy.template.GroovyTemplateAutoConfiguration,\ org.springframework.boot.autoconfigure.jersey.JerseyAutoConfiguration,\ org.springframework.boot.autoconfigure.jooq.JooqAutoConfiguration,\ org.springframework.boot.autoconfigure.kafka.KafkaAutoConfiguration,\ org.springframework.boot.autoconfigure.ldap.embedded.EmbeddedLdapAutoConfiguration,\ org.springframework.boot.autoconfigure.ldap.LdapAutoConfiguration,\ org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration,\ org.springframework.boot.autoconfigure.mail.MailSenderAutoConfiguration,\ org.springframework.boot.autoconfigure.mail.MailSenderValidatorAutoConfiguration,\ org.springframework.boot.autoconfigure.mobile.DeviceResolverAutoConfiguration,\ org.springframework.boot.autoconfigure.mobile.DeviceDelegatingViewResolverAutoConfiguration,\ org.springframework.boot.autoconfigure.mobile.SitePreferenceAutoConfiguration,\ org.springframework.boot.autoconfigure.mongo.embedded.EmbeddedMongoAutoConfiguration,\ org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration,\ org.springframework.boot.autoconfigure.mustache.MustacheAutoConfiguration,\ org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration,\ org.springframework.boot.autoconfigure.reactor.ReactorAutoConfiguration,\ org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration,\ org.springframework.boot.autoconfigure.security.SecurityFilterAutoConfiguration,\ org.springframework.boot.autoconfigure.security.FallbackWebSecurityAutoConfiguration,\ org.springframework.boot.autoconfigure.security.oauth2.OAuth2AutoConfiguration,\ org.springframework.boot.autoconfigure.sendgrid.SendGridAutoConfiguration,\ org.springframework.boot.autoconfigure.session.SessionAutoConfiguration,\ org.springframework.boot.autoconfigure.social.SocialWebAutoConfiguration,\ org.springframework.boot.autoconfigure.social.FacebookAutoConfiguration,\ org.springframework.boot.autoconfigure.social.LinkedInAutoConfiguration,\ org.springframework.boot.autoconfigure.social.TwitterAutoConfiguration,\ org.springframework.boot.autoconfigure.solr.SolrAutoConfiguration,\ org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration,\ org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration,\ org.springframework.boot.autoconfigure.transaction.jta.JtaAutoConfiguration,\ org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration,\ org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration,\ org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration,\ org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration,\ org.springframework.boot.autoconfigure.web.HttpEncodingAutoConfiguration,\ org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration,\ org.springframework.boot.autoconfigure.web.MultipartAutoConfiguration,\ org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration,\ org.springframework.boot.autoconfigure.web.WebClientAutoConfiguration,\ org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration,\ org.springframework.boot.autoconfigure.websocket.WebSocketAutoConfiguration,\ org.springframework.boot.autoconfigure.websocket.WebSocketMessagingAutoConfiguration,\ org.springframework.boot.autoconfigure.webservices.WebServicesAutoConfiguration # Failure analyzers org.springframework.boot.diagnostics.FailureAnalyzer=\ org.springframework.boot.autoconfigure.diagnostics.analyzer.NoSuchBeanDefinitionFailureAnalyzer,\ org.springframework.boot.autoconfigure.jdbc.DataSourceBeanCreationFailureAnalyzer,\ org.springframework.boot.autoconfigure.jdbc.HikariDriverConfigurationFailureAnalyzer # Template availability providers org.springframework.boot.autoconfigure.template.TemplateAvailabilityProvider=\ org.springframework.boot.autoconfigure.freemarker.FreeMarkerTemplateAvailabilityProvider,\ org.springframework.boot.autoconfigure.mustache.MustacheTemplateAvailabilityProvider,\ org.springframework.boot.autoconfigure.groovy.template.GroovyTemplateAvailabilityProvider,\ org.springframework.boot.autoconfigure.thymeleaf.ThymeleafTemplateAvailabilityProvider,\ org.springframework.boot.autoconfigure.web.JspTemplateAvailabilityProvider
spring-boot-autoconfigure-1.5.19.RELEASE.jar!/META-INF/spring.factories
执行SpringApplication.run()
执行 org.springframework.boot.SpringApplication#run(java.lang.String...) 方法:
public ConfigurableApplicationContext run(String... args) {
StopWatch stopWatch = new StopWatch();
stopWatch.start();
// 声明一个 IoC 容器
ConfigurableApplicationContext context = null;
FailureAnalyzers analyzers = null;
// AWT 相关
configureHeadlessProperty();
// 通过 getSpringFactoriesInstances 从类路径下找到 META-INF/spring.factories 配置的所有 SpringApplicationRunListener 类并反射创建实例返回
SpringApplicationRunListeners listeners = getRunListeners(args);
// 回调执行所有 SpringApplicationRunListener 实例的 starting 方法
listeners.starting();
try {
// 封装命令行参数
ApplicationArguments applicationArguments = new DefaultApplicationArguments(
args);
// 准备环境,创建环境完成后在该方法中又回调执行了所有 SpringApplicationRunListener 实例的 environmentPrepared 方法,表示环境准备完成
ConfigurableEnvironment environment = prepareEnvironment(listeners,
applicationArguments);
// 控制台打印 SpringBoot 图标
Banner printedBanner = printBanner(environment);
// 根据当前环境的不同创建不同类型的 IoC 容器
context = createApplicationContext();
// 初始化异常分析器
analyzers = new FailureAnalyzers(context);
// 准备上下文环境:
// 1、将 environment 保存到了 context 即 IoC 容器中
// 2、通过 applyInitializers(context) 方法,执行了所有 ApplicationContextInitializer 实例的 initialize(context) 方法(这些 ApplicationContextInitializer 实例是在初始化 SpringApplication 实例时创建保存的)
// 3、还会回调执行所有 SpringApplicationRunListener 实例的 contextPrepared(context) 方法
// 4、在 prepareContext 方法最后一行还会回调执行所有 SpringApplicationRunListener 实例的 contextLoaded(context) 方法
prepareContext(context, environment, listeners, applicationArguments,
printedBanner);
// 刷新 IoC 容器,IoC 容器初始化,扫描、创建、加载所有组件(配置类、自动配置功能),如果是 web 应用,在这一步还会创建嵌入式 Servlet 容器
refreshContext(context);
// 刷新后处理,会通过 callRunners(context, args) 方法从 IoC 容器中获取所有 ApplicationRunner 和 CommandLineRunner 的 bean,并回调它们的 run 方法
afterRefresh(context, applicationArguments);
// 回调执行所有的 SpringApplicationRunListener 实例的 finished 方法,表示应用启动完成
listeners.finished(context, null);
stopWatch.stop();
if (this.logStartupInfo) {
new StartupInfoLogger(this.mainApplicationClass)
.logStarted(getApplicationLog(), stopWatch);
}
// 整个 SpringBoot 应用启动完成后返回 IoC 容器
return context;
}
catch (Throwable ex) {
handleRunFailure(context, listeners, analyzers, ex);
throw new IllegalStateException(ex);
}
}
总结:
在 SpringBoot 应用启动的过程中会回调一些我们预配置组件的指定方法,这些组件可以是我们配置在指定文件中的类,也可以是我们注册到 IoC 容器的 bean。分类如下:
配置在 META-INF/spring.factories 中:
- org.springframework.context.ApplicationContextInitializer
- org.springframework.context.ApplicationListener
- org.springframework.boot.SpringApplicationRunListener
注册在 IoC 容器中:
- org.springframework.boot.ApplicationRunner
- org.springframework.boot.CommandLineRunner
执行的方法按回调顺序排序如下:
- SpringApplicationRunListener.starting()
- SpringApplicationRunListener.environmentPrepared()
- ApplicationContextInitializer.initialize()
- SpringApplicationRunListener.contextPrepared()
- SpringApplicationRunListener.contextLoaded()
- ApplicationRunner.run()
- CommandLineRunner.run()
- SpringApplicationRunListener.finished()
自定义starter
了解了 SpringBoot 程序的启动流程后,我们也可以自己编写一个 starter 了,下面为一个小案例,功能是让程序在启动时注册一个 hello 组件,并且能通过配置修改输出内容。
创建自动配置组件
1、使用 maven 创建一个 SpringBoot 程序作为自动配置组件,依赖如下:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.19.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.zze.springboot</groupId>
<artifactId>mystarter_autoconfigure</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>mystarter_autoconfigure</name>
<description>Demo project for Spring Boot</description>
<packaging>jar</packaging>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<!--引入 spring-boot-starter-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
</dependencies>
</project>
pom.xml
2、编写与配置文件属性映射的配置类:
package com.zze.springboot.config;
import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties(prefix = "com.zze")
public class HelloProperties {
private String name;
private String remark;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
}
com.zze.springboot.config.HelloProperties
3、编写 hello 服务:
package com.zze.springboot.service;
import com.zze.springboot.config.HelloProperties;
public class HelloService {
private HelloProperties helloProperties;
public void setHelloProperties(HelloProperties helloProperties) {
this.helloProperties = helloProperties;
}
public void sayHello() {
System.out.println("hello " + helloProperties.getName() + " " + helloProperties.getRemark());
}
}
com.zze.springboot.service.HelloService
4、编写自动配置类:
package com.zze.springboot.autoconfigure;
import com.zze.springboot.config.HelloProperties;
import com.zze.springboot.service.HelloService;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* 自定义自动配置类
*/
@EnableConfigurationProperties(HelloProperties.class) // 启用指定类的配置映射,并将配置类实例注册到 IoC 容器
@Configuration
@ConditionalOnWebApplication // web 应用时才生效
public class MyStarterAutoConfiguration {
private HelloProperties helloProperties;
public MyStarterAutoConfiguration(HelloProperties helloProperties){
this.helloProperties = helloProperties;
}
// 注册 hello 服务到 IoC 容器
@Bean
public HelloService helloService(){
HelloService helloService = new HelloService();
helloService.setHelloProperties(helloProperties);
return helloService;
}
}
com.zze.springboot.autoconfigure.MyStarterAutoConfiguration
5、配置自动配置类,让程序启动时加载自动配置类让其生效:
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ com.zze.springboot.autoconfigure.MyStarterAutoConfiguration
META-INF/spring.factories
创建starter工程
1、创建普通的 maven 项目作为 starter 组件,引入上面编写的自动配置组件依赖:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.zze.springboot</groupId>
<artifactId>mystarter</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<!--引入自动配置模块-->
<dependency>
<groupId>com.zze.springboot</groupId>
<artifactId>mystarter_autoconfigure</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
pom.xml
2、将自动配置组件及 starter 组件安装到 maven 仓库。
测试
1、使用 maven 新创建一个 SpringBoot 项目,引入我们编写的 starter 依赖:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.19.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.zze.springboot</groupId>
<artifactId>mystarter</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
pom.xml
2、配置 hello 服务所需要的相关属性:
com.zze.name=张三 com.zze.remark=会员
application.properties
3、直接注入 hello 服务,测试:
package com.example.demo;
import com.zze.springboot.service.HelloService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class DemoApplicationTests {
@Autowired
private HelloService helloService;
@Test
public void contextLoads() {
helloService.sayHello();
/*
hello 张三 会员
*/
}
}
test
- 启动器模块是一个空 jar 文件,仅提供辅助性依赖管理,这些依赖可能用于自动装配或其它类库。启动器依赖于自动配置,第三方使用只需要引入启动器。
- 自动配置类能加载的前提是要将其配置在 META-INF/spring.factories 文件中的 org.springframework.boot.autoconfigure.EnableAutoConfiguration 节下。
java框架之SpringBoot(10)-启动流程及自定义starter的更多相关文章
- SpringBoot IoC启动流程、初始化过程及Bean生命周期各个阶段的作用
目录 SpringBoot IoC启动流程.初始化过程及Bean生命周期各个阶段的作用 简述 首先明确IoC容器是啥 准备-SpringApplication的实例化 启动-SpringApplica ...
- SpringBoot的启动流程是怎样的?SpringBoot源码(七)
注:该源码分析对应SpringBoot版本为2.1.0.RELEASE 1 温故而知新 本篇接 SpringBoot内置的各种Starter是怎样构建的? SpringBoot源码(六) 温故而知新, ...
- java框架之SpringBoot(2)-配置
规范 SpringBoot 使用一个全局的配置文件,配置文件名固定为 application.properties 或 application.yml .比如我们要配置程序启动使用的端口号,如下: s ...
- SpringBoot的启动流程分析(2)
我们来分析SpringApplication启动流程中的run()方法,代码如下 public ConfigurableApplicationContext run(String... args) { ...
- SpringBoot的启动流程分析(1)
通过分析我们可以找到 org.springframework.boot.SpringApplication 中如下, public static ConfigurableApplicationCont ...
- SpringBoot之旅第六篇-启动原理及自定义starter
一.引言 SpringBoot的一大优势就是Starter,由于SpringBoot有很多开箱即用的Starter依赖,使得我们开发变得简单,我们不需要过多的关注框架的配置. 在日常开发中,我们也会自 ...
- linux启动流程及自定义gurb
linux 启动流程 POST BIOS(boot sequence) 所选择的启动设备次序的MBR中是否有引导程序, ----> MBR(bootloader) 提供内核列表 -------& ...
- springboot项目启动之后初始化自定义配置类
前言 今天在写项目的时候,需要再springboot项目启动之后,加载我自定义的配置类的一些方法,百度了之后特此记录下. 正文 方法有两种: 1. 创建自定义类实现 CommandLineRunner ...
- java框架之SpringBoot(1)-入门
简介 Spring Boot 用来简化 Spring 应用开发,约定大于配置,去繁从简,just run 就能创建一个独立的.产品级别的应用. 背景: J2EE 笨重的开发.繁多的配置.低下的开发效率 ...
随机推荐
- .NET HttpGet 获取服务器文件下的图片信息 同步和异步方式处理
/// <summary> /// 项目文件夹下路径 返回流类型数据,如:图片类型 /// </summary> /// <returns></returns ...
- 【原创 Hadoop&Spark 动手实践 8】Spark 应用经验、调优与动手实践
[原创 Hadoop&Spark 动手实践 7]Spark 应用经验.调优与动手实践 目标: 1. 了解Spark 应用经验与调优的理论与方法,如果遇到Spark调优的事情,有理论思考框架. ...
- IndexedDB 教程
IndexedDB 教程 IndexedDB 是一个基于 JavaScript 的面向对象的事务型数据库.有了 LocalStorage 和 Cookies,为什么还要推出 indexedDB 呢?其 ...
- Syncfusion SfDataGrid 导出Excel
var options = new ExcelExportingOptions { ExcelVersion = ExcelVersion.Excel2013, }; //不需要导出的字段 optio ...
- MySQL查询where条件的顺序对查询效率的影响<转>
看到有资料说,where条件的顺序会影响查询的效率,根据的逻辑是: where条件的运行是从右到左的,将选择性强的条件放到最右边,可以先过滤掉大部分的数据(而选择性不强的条件过滤后的结果集仍然很大), ...
- 程序员自己编写的类和JDK类是一种合作关系。
封装类: JAVA为每一个简单数据类型提供了一个封装类,使每个简单数据类型可以被Object来装载. 除了int和char,其余类型首字母大写即成封装类. 转换字符的方式: int I=10; Str ...
- spring-boot项目建立
使用idea来开发spring-boot项目,对于community版本的idea,由于没有spring-boot插件,所有对于开发spring-boot的web项目来说不是很方便,所以安装Ultim ...
- laravel5.8笔记七:语言包
语言包控制config/app.php 'locale' => 'en', 语言包位置:resources/lang/cn/ 建立resources/lang/cn/common.php < ...
- 蜕变成蝶~Linux设备驱动之按键设备驱动
在上述的驱动系列博客中,我们已经了解了关于阻塞和非阻塞.异步通知.轮询.内存和I/O口访问.并发控制等知识,按键设备驱动相对来说是比较简单的,本章内容可以加深我们对字符设备驱动架构.阻塞与非阻塞.中断 ...
- vue双向绑定的时候把遍历的数组转为了字符串,并且再转回去数组进行绑定
我的问题大家可能不太懂,我详细再解释一下,就是我通过遍历一个大的数组,多层遍历之后,最后的值还是一个小的数组,形如: aaa:[ { bbb1:[ "111","&quo ...