我是靠谱客的博主 碧蓝大门,最近开发中收集的这篇文章主要介绍艾编程coding老师课堂笔记:SpringBoot源码深度解析,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

思想:有道无术,术尚可求,有术无道,止于术!

Spring

开源框架,解决企业级开发的复杂性的问题,简化开发

AOP, IOC

Spring 配置越来多,配置不方便管理!

 

Javaweb---Servlet+tomcat + Struct2 SpringMVC SPRINGboot.....

所有的技术框架:从一个复杂的场景慢慢的衍生出来一种规范!简单的配置!

==SpringBoot : 自动配置!==

Springboot怎么自动配置,核心原理!当之无愧的Java领域最热门的技术!公司,怎么演进架构!

 

1、 版本控制

资源控制

 

1

2

3

4

5

6

<parent>

        <groupId>org.springframework.boot</groupId>

        <artifactId>spring-boot-starter-parent</artifactId>

        <version>2.2.1.RELEASE</version>

        <relativePath/> <!-- lookup parent from repository -->

    </parent>

  

资源控制

  <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.2.1.RELEASE</version>
<relativePath>../../spring-boot-dependencies</relativePath>
</parent>
​
<properties>
<activemq.version>5.15.10</activemq.version>
<antlr2.version>2.7.7</antlr2.version>
<appengine-sdk.version>1.9.76</appengine-sdk.version>
<artemis.version>2.10.1</artemis.version>
<aspectj.version>1.9.4</aspectj.version>
<assertj.version>3.13.2</assertj.version>
<atomikos.version>4.0.6</atomikos.version>
<awaitility.version>4.0.1</awaitility.version>
<bitronix.version>2.1.4</bitronix.version>
<build-helper-maven-plugin.version>3.0.0</build-helper-maven-plugin.version>
<byte-buddy.version>1.10.2</byte-buddy.version>
<caffeine.version>2.8.0</caffeine.version>
<cassandra-driver.version>3.7.2</cassandra-driver.version>
<classmate.version>1.5.1</classmate.version>
<commons-codec.version>1.13</commons-codec.version>
<commons-dbcp2.version>2.7.0</commons-dbcp2.version>
<commons-lang3.version>3.9</commons-lang3.version>
<commons-pool.version>1.6</commons-pool.version>
<commons-pool2.version>2.7.0</commons-pool2.version>
<couchbase-cache-client.version>2.1.0</couchbase-cache-client.version>
<couchbase-client.version>2.7.9</couchbase-client.version>
<db2-jdbc.version>11.5.0.0</db2-jdbc.version>
<dependency-management-plugin.version>1.0.8.RELEASE</dependency-management-plugin.version>
<derby.version>10.14.2.0</derby.version>
<dropwizard-metrics.version>4.1.1</dropwizard-metrics.version>
<ehcache.version>2.10.6</ehcache.version>
<ehcache3.version>3.8.1</ehcache3.version>
<elasticsearch.version>6.8.4</elasticsearch.version>
<embedded-mongo.version>2.2.0</embedded-mongo.version>
<exec-maven-plugin.version>1.6.0</exec-maven-plugin.version>
<flatten-maven-plugin.version>1.1.0</flatten-maven-plugin.version>
<flyway.version>6.0.8</flyway.version>
<freemarker.version>2.3.29</freemarker.version>
<git-commit-id-plugin.version>3.0.1</git-commit-id-plugin.version>
<glassfish-el.version>3.0.3</glassfish-el.version>
<glassfish-jaxb.version>2.3.2</glassfish-jaxb.version>
<groovy.version>2.5.8</groovy.version>
<gson.version>2.8.6</gson.version>
<h2.version>1.4.200</h2.version>
<hamcrest.version>2.1</hamcrest.version>
<hazelcast.version>3.12.4</hazelcast.version>
<hazelcast-hibernate5.version>1.3.2</hazelcast-hibernate5.version>
<hibernate.version>5.4.8.Final</hibernate.version>
<hibernate-validator.version>6.0.18.Final</hibernate-validator.version>
<hikaricp.version>3.4.1</hikaricp.version>
<hsqldb.version>2.5.0</hsqldb.version>
<htmlunit.version>2.36.0</htmlunit.version>
<httpasyncclient.version>4.1.4</httpasyncclient.version>
<httpclient.version>4.5.10</httpclient.version>
<httpcore.version>4.4.12</httpcore.version>
<infinispan.version>9.4.16.Final</infinispan.version>
<influxdb-java.version>2.15</influxdb-java.version>
<jackson.version>2.10.0</jackson.version>
<jackson-bom.version>${jackson.version}</jackson-bom.version>
<jakarta-activation.version>1.2.1</jakarta-activation.version>
<jakarta-annotation.version>1.3.5</jakarta-annotation.version>
<jakarta-jms.version>2.0.3</jakarta-jms.version>
<jakarta-json.version>1.1.6</jakarta-json.version>
<jakarta-json-bind.version>1.0.2</jakarta-json-bind.version>
<jakarta-mail.version>1.6.4</jakarta-mail.version>
<jakarta-persistence.version>2.2.3</jakarta-persistence.version>
<jakarta-servlet.version>4.0.3</jakarta-servlet.version>
<jakarta-servlet-jsp.version>2.3.5</jakarta-servlet-jsp.version>
<jakarta-servlet-jsp-jstl.version>1.2.7</jakarta-servlet-jsp-jstl.version>
<jakarta-transaction.version>1.3.3</jakarta-transaction.version>
<jakarta-validation.version>2.0.1</jakarta-validation.version>
<jakarta-websocket.version>1.1.2</jakarta-websocket.version>
<jakarta-ws-rs.version>2.1.6</jakarta-ws-rs.version>
<jakarta-xml-bind.version>2.3.2</jakarta-xml-bind.version>
<jakarta-xml-ws.version>2.3.2</jakarta-xml-ws.version>
<janino.version>3.1.0</janino.version>
<javax-activation.version>1.2.0</javax-activation.version>
<javax-annotation.version>1.3.2</javax-annotation.version>
<javax-cache.version>1.1.1</javax-cache.version>
<javax-jaxb.version>2.3.1</javax-jaxb.version>
<javax-jaxws.version>2.3.1</javax-jaxws.version>
<javax-jms.version>2.0.1</javax-jms.version>
<javax-json.version>1.1.4</javax-json.version>
<javax-jsonb.version>1.0</javax-jsonb.version>
<javax-mail.version>1.6.2</javax-mail.version>
<javax-money.version>1.0.3</javax-money.version>
<javax-persistence.version>2.2</javax-persistence.version>
<javax-transaction.version>1.3</javax-transaction.version>
<javax-validation.version>2.0.1.Final</javax-validation.version>
<javax-websocket.version>1.1</javax-websocket.version>
<jaxen.version>1.2.0</jaxen.version>
<jaybird.version>3.0.6</jaybird.version>
<jboss-logging.version>3.4.1.Final</jboss-logging.version>
<jboss-transaction-spi.version>7.6.0.Final</jboss-transaction-spi.version>
<jdom2.version>2.0.6</jdom2.version>
<jedis.version>3.1.0</jedis.version>
<jersey.version>2.29.1</jersey.version>
<jest.version>6.3.1</jest.version>
<jetty.version>9.4.22.v20191022</jetty.version>
<jetty-el.version>8.5.40</jetty-el.version>
<jetty-jsp.version>2.2.0.v201112011158</jetty-jsp.version>
<jetty-reactive-httpclient.version>1.0.3</jetty-reactive-httpclient.version>
<jmustache.version>1.15</jmustache.version>
<jna.version>4.5.2</jna.version>
<joda-time.version>2.10.5</joda-time.version>
<johnzon.version>${johnzon-jsonb.version}</johnzon.version>
<johnzon-jsonb.version>1.2.1</johnzon-jsonb.version>
<jolokia.version>1.6.2</jolokia.version>
<jooq.version>3.12.3</jooq.version>
<jsonassert.version>1.5.0</jsonassert.version>
<json-path.version>2.4.0</json-path.version>
<jstl.version>1.2</jstl.version>
<jtds.version>1.3.1</jtds.version>
<junit.version>4.12</junit.version>
<junit-jupiter.version>5.5.2</junit-jupiter.version>
<kafka.version>2.3.1</kafka.version>
<kotlin.version>1.3.50</kotlin.version>
<kotlin-coroutines.version>1.3.2</kotlin-coroutines.version>
<lettuce.version>5.2.1.RELEASE</lettuce.version>
<liquibase.version>3.8.0</liquibase.version>
<log4j2.version>2.12.1</log4j2.version>
<logback.version>1.2.3</logback.version>
<lombok.version>1.18.10</lombok.version>
<mariadb.version>2.4.4</mariadb.version>
<maven-antrun-plugin.version>1.8</maven-antrun-plugin.version>
<maven-assembly-plugin.version>3.1.1</maven-assembly-plugin.version>
<maven-clean-plugin.version>3.1.0</maven-clean-plugin.version>
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
<maven-dependency-plugin.version>3.1.1</maven-dependency-plugin.version>
<maven-deploy-plugin.version>2.8.2</maven-deploy-plugin.version>
<maven-enforcer-plugin.version>3.0.0-M2</maven-enforcer-plugin.version>
<maven-failsafe-plugin.version>2.22.2</maven-failsafe-plugin.version>
<maven-help-plugin.version>3.2.0</maven-help-plugin.version>
<maven-install-plugin.version>2.5.2</maven-install-plugin.version>
<maven-invoker-plugin.version>3.2.1</maven-invoker-plugin.version>
<maven-jar-plugin.version>3.1.2</maven-jar-plugin.version>
<maven-javadoc-plugin.version>3.1.1</maven-javadoc-plugin.version>
<maven-resources-plugin.version>3.1.0</maven-resources-plugin.version>
<maven-shade-plugin.version>3.2.1</maven-shade-plugin.version>
<maven-site-plugin.version>3.8.2</maven-site-plugin.version>
<maven-source-plugin.version>3.1.0</maven-source-plugin.version>
<maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
<maven-war-plugin.version>3.2.3</maven-war-plugin.version>
<micrometer.version>1.3.1</micrometer.version>
<mimepull.version>1.9.12</mimepull.version>
<mockito.version>3.1.0</mockito.version>
<mongodb.version>3.11.2</mongodb.version>
<mongo-driver-reactivestreams.version>1.12.0</mongo-driver-reactivestreams.version>
<mssql-jdbc.version>7.4.1.jre8</mssql-jdbc.version>
<mysql.version>8.0.18</mysql.version>
<nekohtml.version>1.9.22</nekohtml.version>
<neo4j-ogm.version>3.2.2</neo4j-ogm.version>
<netty.version>4.1.43.Final</netty.version>
<netty-tcnative.version>2.0.26.Final</netty-tcnative.version>
<nio-multipart-parser.version>1.1.0</nio-multipart-parser.version>
<ojdbc.version>19.3.0.0</ojdbc.version>
<okhttp3.version>3.14.4</okhttp3.version>
<pooled-jms.version>1.0.6</pooled-jms.version>
<postgresql.version>42.2.8</postgresql.version>
<prometheus-pushgateway.version>0.7.0</prometheus-pushgateway.version>
<quartz.version>2.3.2</quartz.version>
<querydsl.version>4.2.1</querydsl.version>
<rabbit-amqp-client.version>5.7.3</rabbit-amqp-client.version>
<reactive-streams.version>1.0.3</reactive-streams.version>
<reactor-bom.version>Dysprosium-SR1</reactor-bom.version>
<rest-assured.version>3.3.0</rest-assured.version>
<rsocket.version>1.0.0-RC5</rsocket.version>
<rxjava.version>1.3.8</rxjava.version>
<rxjava2.version>2.2.14</rxjava2.version>
<rxjava-adapter.version>1.2.1</rxjava-adapter.version>
<saaj-impl.version>1.5.1</saaj-impl.version>
<selenium.version>3.141.59</selenium.version>
<selenium-htmlunit.version>2.36.0</selenium-htmlunit.version>
<sendgrid.version>4.4.1</sendgrid.version>
<servlet-api.version>4.0.1</servlet-api.version>
<slf4j.version>1.7.29</slf4j.version>
<snakeyaml.version>1.25</snakeyaml.version>
<solr.version>8.2.0</solr.version>
<spring-amqp.version>2.2.1.RELEASE</spring-amqp.version>
<spring-batch.version>4.2.0.RELEASE</spring-batch.version>
<spring-cloud-connectors.version>2.0.6.RELEASE</spring-cloud-connectors.version>
<spring-data-releasetrain.version>Moore-SR1</spring-data-releasetrain.version>
<spring-framework.version>5.2.1.RELEASE</spring-framework.version>
<spring-hateoas.version>1.0.1.RELEASE</spring-hateoas.version>
<spring-integration.version>5.2.1.RELEASE</spring-integration.version>
<spring-kafka.version>2.3.3.RELEASE</spring-kafka.version>
<spring-ldap.version>2.3.2.RELEASE</spring-ldap.version>
<spring-restdocs.version>2.0.4.RELEASE</spring-restdocs.version>
<spring-retry.version>1.2.4.RELEASE</spring-retry.version>
<spring-security.version>5.2.1.RELEASE</spring-security.version>
<spring-session-bom.version>Corn-RELEASE</spring-session-bom.version>
<spring-ws.version>3.0.8.RELEASE</spring-ws.version>
<sqlite-jdbc.version>3.28.0</sqlite-jdbc.version>
<sun-mail.version>${jakarta-mail.version}</sun-mail.version>
<thymeleaf.version>3.0.11.RELEASE</thymeleaf.version>
<thymeleaf-extras-data-attribute.version>2.0.1</thymeleaf-extras-data-attribute.version>
<thymeleaf-extras-java8time.version>3.0.4.RELEASE</thymeleaf-extras-java8time.version>
<thymeleaf-extras-springsecurity.version>3.0.4.RELEASE</thymeleaf-extras-springsecurity.version>
<thymeleaf-layout-dialect.version>2.4.1</thymeleaf-layout-dialect.version>
<tomcat.version>9.0.27</tomcat.version>
<unboundid-ldapsdk.version>4.0.12</unboundid-ldapsdk.version>
<undertow.version>2.0.27.Final</undertow.version>
<versions-maven-plugin.version>2.7</versions-maven-plugin.version>
<webjars-hal-browser.version>3325375</webjars-hal-browser.version>
<webjars-locator-core.version>0.41</webjars-locator-core.version>
<wsdl4j.version>1.6.3</wsdl4j.version>
<xml-maven-plugin.version>1.0.2</xml-maven-plugin.version>
<xmlunit2.version>2.6.3</xmlunit2.version>
</properties>

 

 

 

pom.xml 就是springboot的版本控制中心!

假设里面有默认的配置,我们就不需手动配置版本了,假设没有,我们才需要手动配置!

 

2、 启动器

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

package com.example.demo;

import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;

//程序的主入口

@SpringBootApplication  //Springboot应用

public class DemoApplication {

    public static void main(String[] args) {

        //开启了一个服务!

        SpringApplication.run(DemoApplication.class, args);

    }

}

  

 

applicationContext.xml == @Configuration

bean == @Bean

import == @Import

 

所有的包,必须在主启动类的同级或子级目录!为什么?

 

1

2

3

4

5

6

7

8

protected List<String> getCandidateConfigurations(AnnotationMetadata metadata, AnnotationAttributes attributes) {

     

    List<String> configurations = SpringFactoriesLoader.loadFactoryNames(getSpringFactoriesLoaderFactoryClass(),

                                                                         getBeanClassLoader());

    Assert.notEmpty(configurations, "No auto configuration classes found in META-INF/spring.factories. If you "

                    "are using a custom packaging, make sure that file is correct.");

    return configurations;

}

  

在springboot已启动,它就自动帮我们配置了以上全部的类!但是真的都生效的了?

1

2

WebMvcAutoConfiguration.xml

    bean

  

怎么自动配置的?

3、SpringApplication

  1. 推断我们的应用是web应用还是 普通应用!

  2. 加载初始化!

  3. 设置监听器

  4. 推断main方法,找到运行的主类

 

run方法()核心!

4、YAML

但为了强调这种语言以数据做为中心

字面量键值对:

1

k: (空格) value

  

对象,map

1

2

3

4

5

6

7

8

9

10

11

# 语法

k:

 v1:

 v2:

  

# 例子

student:

  name: coding

  age: 3

  

student: {name: coding, age: 3}

  

数组(List,Set)

1

2

3

4

5

6

7

#语法

pets:

 - cat

 - dog

 - pig

  

pets: [cat,dog,pig]

  

@ConfigurationProperties :SpringBoot自动配置底层全部都是这个注解

 @ConfigurationProperties@Value
功能批量从配置文件中注入属性一个个指定
松散绑定支持不支持
SpEL不支持支持
JSR303数据校验支持不支持
复杂类型封装支持不支持!
   

 

精髓

@ConditionalOnXXX根据这个类中不同的条件判断这个类是否生效!

 

  1. 一旦这个配置类生效,这个配置类就会往容器中添加各种组件!

  2. 这些个组件,都可以和xxxProerties绑定,而 xxProerties @ConfigurationProperties 和我们的配置文件绑定,所以说,我们只需要少量配置就可以实现功能了,假设不配置,就会使用springboot 的默认配置

  3. Springboot中存在大量自动动配置类

    但是这些类不一定生效! @ConditionalOnXXX

  4. xxxAutoConfiguration,自动配置类

  5. xxxProperties,配置类 @ConfigurationProperties 组合

  6. 实现和我们的配置一一对应,我们假设没有配置就使用自动配置,如果配置了,就使用我们自动配置的!

 

架构演进推演

聊聊过去和未来!

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

三层架构  mvc

    架构---> 结构

     

开发框架

    Spring

        IOC:控制反转思想  DI

            约泡:

                泡温泉,泡茶,。。。。泡友

                附近的人,打招呼,加微信,聊聊天天聊,,,,,约泡   手动实现,一步步new

             

            浴场: 温泉,茶庄的... 容器(get 拿)

                直接有泡友了!

                 

            原来需要一步步自己去操作,现在交个容器了,我们需要什么区拿就可以了!

             

        AOP: 面向切面 (动态代理)

            不影响原来业务的情况下,动态增加功能,日志,事务,安全///.

     

    解决企业开发的复杂性

    Spring 春天,简化了开发,随着时间的推移,开始慢慢的复杂起来,配置文件变多!

     

    SpringBoot

        SpringBoot 并不是新的东西,就是Spring升级版!

        新一代JavaEE开发标准,开箱即用!

        自动配置=====核心原理!

        约定大于配置

         

单体架构  all in one

微服务架构---新架构

    模块化,功能化!

    代码没有变化,网络问题

     

     

     

微服务架构的问题? 4步曲

    1. 这么多服务,客户端如何去访问?

    2. 这么多服务,服务之间如何通信?

    3. 这么多服务,怎么治理?

    4. 这么多服务,服务挂了怎么办?

     

     

SpringCloud, 生态.,

解决方案:

    1. Spring Cloud Netflix  一站式解决方案

        api:----zuul

        Feign---》 HttpClient =-- Http 的同学方式,同步并阻塞

        服务注册与发现====》Eureka

        熔断机制====》Hystrix

         

        Netflix 2018,宣布无限期停止维护!

         

    2. Apache Dubbo + Zookeeper  不完善!

        API;没有  借助别人的或者自己写

        Dubbo:异步非阻塞 RPC

        服务注册与发现: Zookeeper (Hadoop,Hive。。。)

        熔断机制没有。借助  Hystrix

     

    3. Spring Cloud Alibaba 一站式解决方案!

     

     

目前又推出新一代的服务网格概念

   下一代的服务标准: Server Mesh  服务网格

   Istio:未来需要掌握

    

   1   1.8  裁员对于优秀的人来说是好事!

    

万变不离其宗!一通百通!

    1. 这么多服务,客户端如何去访问?

    2. 这么多服务,服务之间如何通信?

    3. 这么多服务,怎么治理?

    4. 这么多服务,服务挂了怎么办?

     

    如果你们机遇这些问题,开发出来一套解决方案!  投资自己

     

为什么要解决这问题: 本质: 网络是不可靠的!

高级程序猿

程序猿---项目经理---架构师----CTO---CEO

架构:设计出来,衍生出来的!

架是一个逐步演进的过程!架构没有最好的,只有最合适!

-----------------------

当下进阶的一个任务!

1、 定义当前企业的架构,所处的阶段,绘制出一个架构图(完成)

2、 清晰定位当前公司的一个状况!根据企业的实际情况绘制出新的架构图(重构!)

分布式

高可用

集群

负载均衡

.....

最后

以上就是碧蓝大门为你收集整理的艾编程coding老师课堂笔记:SpringBoot源码深度解析的全部内容,希望文章能够帮你解决艾编程coding老师课堂笔记:SpringBoot源码深度解析所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(47)

评论列表共有 0 条评论

立即
投稿
返回
顶部