無錫網(wǎng)站建設(shè)制作開發(fā)廣西seo搜索引擎優(yōu)化
一、思想
? ? ? 我們看到技術(shù)上高效簡單的使用,其實背后除了奇思妙想的開創(chuàng)性設(shè)計,另一點是別人幫你做了復(fù)雜繁瑣的事情。
二、從官網(wǎng)Demo入手
? ? ? ? 官網(wǎng)就一行代碼。這個就是它的啟動代碼。
?
? ? ? ? 1、@SpringBootApplication注解
? ? ? ? ? ? ? ? ①.? 三個核心注解的整合。
????????????????????????@SpringBootConfiguration ?(配置注入)
????????????????????????@ComponentScan(包下bean組件掃描)
????????????????????????@EnableAutoConfiguration? ? ?(開啟自動配置)
? ? ? ? ? ? ? ? ? ? ? ? (每一個注解都是一個故事,目前咱們只是窺探輪廓)
????????????????
?????????2、Run代碼
? ? ? ? ? ? ? ? ? ? ? ? ① 加載配置文件
? ? ? ? ? ? ? ? ? ? ? ? ②? 裝載Bean容器,以及監(jiān)聽器啟動在其中監(jiān)控對象的創(chuàng)建過程。
? ? ? ? ? ? ? ? ? ? ? ? ③? 加載所有的注解的bean以及自動配置的spring.factories 設(shè)置的所有bean
? ? ? ? ? ? ? ? ? ? ? ? ④ 把應(yīng)用放入內(nèi)嵌的tomcat服務(wù)中
public ConfigurableApplicationContext run(String... args) {StopWatch stopWatch = new StopWatch();stopWatch.start();ConfigurableApplicationContext context = null;Collection<SpringBootExceptionReporter> exceptionReporters = new ArrayList();this.configureHeadlessProperty();SpringApplicationRunListeners listeners = this.getRunListeners(args);listeners.starting();Collection exceptionReporters;try {ApplicationArguments applicationArguments = new DefaultApplicationArguments(args);ConfigurableEnvironment environment = this.prepareEnvironment(listeners, applicationArguments);this.configureIgnoreBeanInfo(environment);Banner printedBanner = this.printBanner(environment);context = this.createApplicationContext();exceptionReporters = this.getSpringFactoriesInstances(SpringBootExceptionReporter.class, new Class[]{ConfigurableApplicationContext.class}, context);this.prepareContext(context, environment, listeners, applicationArguments, printedBanner);this.refreshContext(context);this.afterRefresh(context, applicationArguments);stopWatch.stop();if (this.logStartupInfo) {(new StartupInfoLogger(this.mainApplicationClass)).logStarted(this.getApplicationLog(), stopWatch);}listeners.started(context);this.callRunners(context, applicationArguments);} catch (Throwable var10) {this.handleRunFailure(context, var10, exceptionReporters, listeners);throw new IllegalStateException(var10);}try {listeners.running(context);return context;} catch (Throwable var9) {this.handleRunFailure(context, var9, exceptionReporters, (SpringApplicationRunListeners)null);throw new IllegalStateException(var9);}}
????????????????????????
?