0%

2 Spring IoC
[2.1 Spring IoC 的基本概念](#2.1 Spring IoC 的基本概念)
[2.2 Spring IoC 容器](#2.2 Spring IoC 容器)
[2.2.1 BeanFactory](#2.2.1 BeanFactory)
[2.2.2 ApplicationContext](#2.2.2 ApplicationContext)
[2.3 依赖注入的类型](#2.3 依赖注入的类型)
[2.3.1 使用构造方法注入](#2.3.1 使用构造方法注入)
[2.3.2 使用属性的 setter 方法注入](#2.3.2 使用属性的 setter 方法注入)
[3 Spring Bean](#3 Spring Bean)
[3.1 Bean 的配置](#3.1 Bean 的配置)
[3.2 Bean 的实例化](#3.2 Bean 的实例化)
[3.2.1 构造方法实例化](#3.2.1 构造方法实例化)
[3.2.2 静态工厂实例化](#3.2.2 静态工厂实例化)
[3.2.3 实例工厂实例化](#3.2.3 实例工厂实例化)
[3.3 Bean 的作用域](#3.3 Bean 的作用域)
[3.3.1 singleton作用域](#3.3.1 singleton作用域)
[3.3.2 prototype作用域](#3.3.2 prototype作用域)
[3.4 Bean 的生命周期](#3.4 Bean 的生命周期)
[3.5 Bean 的装配方式](#3.5 Bean 的装配方式)
[3.5.1 基于 XML 配置的装配](#3.5.1 基于 XML 配置的装配)
[3.5.2 基于注解的装配](#3.5.2 基于注解的装配)
[4 Spring AOP](#4 Spring AOP)
[4.1 Spring AOP 的基本概念](#4.1 Spring AOP 的基本概念)
[4.1.1 AOP 的概念](#4.1.1 AOP 的概念)
[4.1.2 AOP 的术语](#4.1.2 AOP 的术语)
[4.2 动态代理](#4.2 动态代理)
[4.2.1 JDK 动态代理](#4.2.1 JDK 动态代理)
[4.2.2 CGLIB](#4.2.2 CGLIB)
[4.3 基于代理类的 AOP 实现](#4.3 基于代理类的 AOP 实现)

阅读全文 »

BOM 对象
顶级对象Window对象
this. 指向
location 对象
navigator对象
history 对象
JS执行机制(事件循环)
offset 偏移量
scroll 系列

阅读全文 »

spring 框架

What can Spring do?

1636868232816

介绍SpringBoot框架

官方文档

查看版本新特性;

https://github.com/spring-projects/spring-boot/wiki#release-notes

spring5 升级

1.引入响应式开发

1636868739459

1.1内部源码设计

基于Java8的一些新特性,如:接口默认实现。重新设计源码架构。

为什么用SpringBoot

Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications that you can “just run”.

能快速创建出生产级别的Spring应用

2.1、SpringBoot优点

  • Create stand-alone Spring applications

    • 创建独立Spring应用
  • Embed Tomcat, Jetty or Undertow directly (no need to deploy WAR files)

    • 内嵌web服务器
  • Provide opinionated ‘starter’ dependencies to simplify your build configuration

    • 自动starter依赖,简化构建配置
  • Automatically configure Spring and 3rd party libraries whenever possible

    • 自动配置Spring以及第三方功能
  • Provide production-ready features such as metrics, health checks, and externalized configuration

    • 提供生产级别的监控、健康检查及外部化配置
  • Absolutely no code generation and no requirement for XML configuration

    • 无代码生成、无需编写XML

SpringBoot是整合Spring技术栈的一站式框架

SpringBoot是简化Spring技术栈的快速开发脚手架

2.2、SpringBoot缺点

  • 人称版本帝,迭代快,需要时刻关注变化
  • 封装太深,内部原理复杂,不容易精通

3.时代背景

3.1微服务

James Lewis and Martin Fowler (2014) 提出微服务完整概念。https://martinfowler.com/microservices

In short, the microservice architectural style is an approach to developing a single application as a suite of small services, each running in its own process and communicating with lightweight mechanisms, often an HTTP resource API. These services are built around business capabilities and independently deployable by fully automated deployment machinery. There is a bare minimum of centralized management of these services, which may be written in different programming languages and use different data storage technologies.– James Lewis and Martin Fowler (2014)

  • 微服务是一种架构风格

  • 一个应用拆分为一组小型服务

  • 每个服务运行在自己的进程内,也就是可独立部署和升级

  • 服务之间使用轻量级HTTP交互

  • 服务围绕业务功能拆分

  • 可以由全自动部署机制独立部署

  • 去中心化,服务自治。服务可以使用不同的语言、不同的存储技术

3.2分布式的困难

  • 远程调用

  • 服务发现

  • 负载均衡

  • 服务容错

  • 配置管理

  • 服务监控

  • 链路追踪

  • 日志管理

  • 任务调度

  • ……

3.2.1分布式的解决

1636870814949

3.3、云原生

原生应用如何上云。 Cloud Native

上云的困难

  • 服务自愈

  • 弹性伸缩

  • 服务隔离

  • 自动化部署

  • 灰度发布

  • 流量治理

  • ……

4.了解自动化配置

1.SpringBoot特点

1.1.依赖配置

  • 父项目做依赖管理

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    依赖管理    
    <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.3.4.RELEASE</version>
    </parent>

    他的父项目
    <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-dependencies</artifactId>
    <version>2.3.4.RELEASE</version>
    </parent>

    几乎声明了所有开发中常用的依赖的版本号,自动版本仲裁机制

  • 开发导入starter场景启动器

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    1、见到很多 spring-boot-starter-* : *就某种场景
    2、只要引入starter,这个场景的所有常规需要的依赖我们都自动引入
    3、SpringBoot所有支持的场景
    https://docs.spring.io/spring-boot/docs/current/reference/html/using-spring-boot.html#using-boot-starter
    4、见到的 *-spring-boot-starter: 第三方为我们提供的简化开发的场景启动器。
    5、所有场景启动器最底层的依赖
    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter</artifactId>
    <version>2.3.4.RELEASE</version>
    <scope>compile</scope>
    </dependency>
  • 无需关注版本号,自动版本仲裁

    1
    2
    1、引入依赖默认都可以不写版本
    2、引入非版本仲裁的jar,要写版本号。
  • 修改配置,默认版本号,如mysql 8.0 ,改为MySQL5.0版本

1
2
3
4
5
1、查看spring-boot-dependencies里面规定当前依赖的版本 用的 key。
2、在当前项目里面重写配置
<properties>
<mysql.version>5.1.43</mysql.version>
</properties>

1.2、自动配置

  • 自动配好Tomcat

    • 引入Tomcat依赖。
    • 配置Tomcat
1
2
3
4
5
6
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<version>2.3.4.RELEASE</version>
<scope>compile</scope>
</dependency>
  • 自动配好SpringMVC

    • 引入SpringMVC全套组件
    • 自动配好SpringMVC常用组件(功能)
  • 自动配好Web常见功能,如:字符编码问题

    • SpringBoot帮我们配置好了所有web开发的常见场景
  • 默认的包结构

    • 主程序所在包及其下面的所有子包里面的组件都会被默认扫描进来
    • 无需以前的包扫描配置
    • 想要改变扫描路径,@SpringBootApplication(scanBasePackages=“com.atguigu”)
      • 或者@ComponentScan 指定扫描路径
1
2
3
4
5
@SpringBootApplication
等同于
@SpringBootConfiguration
@EnableAutoConfiguration
@ComponentScan("com.atguigu.boot")
  • 各种配置拥有默认值

    • 默认配置最终都是映射到某个类上,如:MultipartProperties
    • 配置文件的值最终会绑定每个类上,这个类会在容器中创建对象
  • 按需加载所有自动配置项

    • 非常多的starter
    • 引入了哪些场景这个场景的自动配置才会开启
    • SpringBoot所有的自动配置功能都在 spring-boot-autoconfigure 包里面
  • ……

数据响应

1.响应json

1.1 jackson.jar+@ResponseBody

1
2
3
4
5
6
7
8
9
10
11
12
        <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
web场景自动引入了json场景
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-json</artifactId>
<version>2.3.4.RELEASE</version>
<scope>compile</scope>
</dependency>

只要给方法添加@ResponseBody 就会给浏览器返回json数据