中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁 > news >正文

水稻網(wǎng)站做go分析網(wǎng)絡(luò)營銷有本科嗎

水稻網(wǎng)站做go分析,網(wǎng)絡(luò)營銷有本科嗎,網(wǎng)站首頁輪播圖怎么做,中國最好的建筑公司目錄 微服務(wù)架構(gòu)時代 快速入門 入門詳解 SpringBoot的自動配置 石器時代:XML配置bean 青銅時代:SpringConfig 鐵器時代:AutoConfigurationImportSelector 手寫簡單Starter SpringApplication啟動原理 微服務(wù)架構(gòu)時代 Spring Boot的…

目錄

微服務(wù)架構(gòu)時代

快速入門

入門詳解

SpringBoot的自動配置

石器時代:XML配置bean

青銅時代:SpringConfig

鐵器時代:AutoConfigurationImportSelector

手寫簡單Starter

SpringApplication啟動原理


微服務(wù)架構(gòu)時代

Spring Boot的出現(xiàn)與微服務(wù)架構(gòu)有關(guān),它是Spring Framework的一部分,旨在簡化開發(fā)獨立的、可執(zhí)行的Java應(yīng)用程序。Spring Boot解決了傳統(tǒng)Java應(yīng)用程序開發(fā)中的繁瑣配置問題,使開發(fā)人員能夠更快速地構(gòu)建微服務(wù)和獨立應(yīng)用程序。

快速入門

如果要快速入門,這個傳送門一定很有幫助------->Spring | Quickstart

入門詳解

Spring入門詳解的部分諸君可以看一下這篇文章:

SpringBoot入門詳解-CSDN博客

SpringBoot的自動配置
石器時代:XML配置bean
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd">
?<!-- 聲明一個名為 myBean 的 Bean --><bean id="myBean" class="com.elaine.MyBean"><property name="name" value="elaine"/></bean>
?
</beans>
青銅時代:SpringConfig
@Configuration
public class MyConfiguration {
?@Beanpublic MyBean myBean() {MyBean bean = new MyBean();bean.setName("Elaine");return bean;}
}
鐵器時代:AutoConfigurationImportSelector

SpringBoot開啟自動配置的注解是@EnableAutoConfiguration,但是自動配置的核心功能是通過AutoConfigurationImportSelector實現(xiàn)的。

@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@AutoConfigurationPackage
@Import({AutoConfigurationImportSelector.class})
public @interface EnableAutoConfiguration {String ENABLED_OVERRIDE_PROPERTY = "spring.boot.enableautoconfiguration";
?Class<?>[] exclude() default {};
?String[] excludeName() default {};
}
  • AutoConfigurationImportSelector實現(xiàn)ImportSelector接口,收集需要導(dǎo)入的配置類,配合@Import將相應(yīng)的類導(dǎo)入到Spring容器中。

  • 獲取注?類的?法是 selectImports(),它實際調(diào)?的是 getAutoConfigurationEntry ,這個?法是獲取?動裝配類的關(guān)鍵,主要流程可以分為這么?步:

    1. 獲取注解的屬性,用于后面的排除

    2. 獲取所有需要?動裝配的配置類的路徑:這?步是最關(guān)鍵的,從 META-INF/spring.factories 獲取?動 配置類的路徑

    3. 去掉重復(fù)的配置類和需要排除的重復(fù)類,把需要?動加載的配置類的路徑存儲起來

    public String[] selectImports(AnnotationMetadata annotationMetadata) {if (!this.isEnabled(annotationMetadata)) {return NO_IMPORTS;} else {AutoConfigurationEntry autoConfigurationEntry = this.getAutoConfigurationEntry(annotationMetadata);return StringUtils.toStringArray(autoConfigurationEntry.getConfigurations());}}
?protected AutoConfigurationEntry getAutoConfigurationEntry(AnnotationMetadata annotationMetadata) {if (!this.isEnabled(annotationMetadata)) {return EMPTY_ENTRY;} else {// 1.獲取注解的屬性AnnotationAttributes attributes = this.getAttributes(annotationMetadata);// 2.獲取需要?動裝配的所有配置類,讀取META-INF/spring.factories,獲取?動配置類路徑List<String> configurations = this.getCandidateConfigurations(annotationMetadata, attributes);// 3.1.移除重復(fù)的配置configurations = this.removeDuplicates(configurations);// 3.2.處理需要排除的配置Set<String> exclusions = this.getExclusions(annotationMetadata, attributes);this.checkExcludedClasses(configurations, exclusions);configurations.removeAll(exclusions);configurations = this.getConfigurationClassFilter().filter(configurations);this.fireAutoConfigurationImportEvents(configurations, exclusions);return new AutoConfigurationEntry(configurations, exclusions);}}
手寫簡單Starter

在了解自動配置的原理后,就簡單地創(chuàng)建一個自定義的spring-boot-starter吧。

文件目錄貼一下:

  1. 創(chuàng)建自動配置類和需要定義的bean。

    @Configuration
    public class MyUserAutoConfiguration {@Beanpublic UserManager userManager(){return new UserManager();}
    }
    public class UserManager {public String sayHello() {return "own-starter:hello.";}
    }
  2. src/main/resources/META-INF/ 目錄下創(chuàng)建一個 spring.factories 文件

    org.springframework.boot.autoconfigure.EnableAutoConfiguration=\com.lloyd.user.MyUserAutoConfiguration
  3. 創(chuàng)建一個spring-web的SpringBoot項目,添加自定義Starter的依賴。

        <dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><!-- 自定義starter的坐標(biāo) --><dependency><groupId>com.lloyd</groupId><artifactId>springboot_06_own_starter</artifactId><version>0.0.1-SNAPSHOT</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency></dependencies>

  4. 創(chuàng)建一個Rest接口進行驗證

    @RestController
    public class UserController {@Autowiredprivate UserManager userManager;
    ?@GetMapping("/user")public String sayHello(){return userManager.sayHello();}
    }

    瀏覽器結(jié)果:

SpringApplication啟動原理

SpringApplication 這個類主要做了以下四件事情:

  1. 推斷應(yīng)?的類型是普通的項?還是 Web 項?

  2. 查找并加載所有可?初始化器 , 設(shè)置到 initializers 屬性中

  3. 找出所有的應(yīng)?程序監(jiān)聽器,設(shè)置到 listeners 屬性中

  4. 推斷并設(shè)置 main ?法的定義類,找到運?的主類

大致流程如下(圖片來自于網(wǎng)絡(luò)):

http://m.risenshineclean.com/news/60646.html

相關(guān)文章:

  • jquery特效網(wǎng)站百度推廣后臺登錄首頁
  • 最好的網(wǎng)站建設(shè)用途上海seo推廣服務(wù)
  • 做自己的網(wǎng)站推廣普通話手抄報模板可打印
  • 濰坊網(wǎng)站建設(shè) 濰坊做網(wǎng)站廣東佛山疫情最新情況
  • 深圳市網(wǎng)站建設(shè)公司深圳百度快速排名提升
  • 香港網(wǎng)站建設(shè)展覽營銷策劃書
  • 做網(wǎng)站需要什么材料網(wǎng)站制作費用多少
  • 時時彩平臺網(wǎng)站怎么做怎么讓某個關(guān)鍵詞排名上去
  • 可以直接玩游戲的網(wǎng)站韓國網(wǎng)站
  • 東營網(wǎng)站制作公司杭州網(wǎng)站
  • 簡單網(wǎng)站建設(shè)模板下載百度關(guān)鍵詞怎么做排名
  • 河南疫情防控最新政策今日頭條新聞搜狗關(guān)鍵詞優(yōu)化軟件
  • 網(wǎng)站的困難app拉新推廣代理平臺
  • 凱天建設(shè)發(fā)展集團有限公司網(wǎng)站盤多多網(wǎng)盤資源庫
  • 品牌網(wǎng)站開發(fā)動態(tài)模塊廣州專業(yè)seo公司
  • 工程公司是做什么的谷歌seo排名技巧
  • 推廣網(wǎng)站掙錢windows優(yōu)化大師手機版
  • 臺州響應(yīng)式建站seo外鏈建設(shè)方法
  • 網(wǎng)站列表頁怎么做內(nèi)鏈搜索引擎排行榜
  • 網(wǎng)站之間的差異seo技術(shù)是干什么的
  • 設(shè)計logo怎么收費泰安seo培訓(xùn)
  • 公司網(wǎng)站設(shè)計案例發(fā)外鏈軟件
  • 有什么做門窗展廳的設(shè)計網(wǎng)站百度收錄權(quán)重
  • 領(lǐng)手工在家做的網(wǎng)站2019廣告推廣的軟件
  • 購卡網(wǎng)頁怎么制作關(guān)鍵詞優(yōu)化軟件
  • 靜態(tài)做網(wǎng)站百度推廣官方網(wǎng)站登錄入口
  • 社交網(wǎng)站百度搜索推廣費用
  • 網(wǎng)站綜合建設(shè)筆記可以免費發(fā)布廣告的平臺有哪些
  • 哈爾濱整站優(yōu)化百度提交入口
  • 汽車網(wǎng)站開發(fā)流程品牌整合營銷傳播