mirror of
https://github.com/Estom/notes.git
synced 2026-04-05 11:57:37 +08:00
修改了工程目录
This commit is contained in:
0
Spring/SpringCloud/SpringCloud简介.md
Normal file
0
Spring/SpringCloud/SpringCloud简介.md
Normal file
0
Spring/SpringMVC/SpringMVC简介.md
Normal file
0
Spring/SpringMVC/SpringMVC简介.md
Normal file
68
Spring/Springboot/1 Springboot.md
Normal file
68
Spring/Springboot/1 Springboot.md
Normal file
@@ -0,0 +1,68 @@
|
||||
## 1 Spring 能做什么
|
||||
> [参考文献](https://www.yuque.com/atguigu/springboot/na3pfd)
|
||||
|
||||
|
||||
### Spring框架的功能
|
||||
|
||||
1. 微服务。实现功能的进一步拆分
|
||||
2. 响应式。异步、非阻塞的框架
|
||||
3. 云计算。分布式云开发Spring cloud
|
||||
4. web开发。Springmvc
|
||||
5. 无服务开发/事件驱动/批处理业务
|
||||
|
||||
|
||||
### Spring全家桶逻辑关系
|
||||
|
||||
1. Spring Data
|
||||
2. SPring cloud
|
||||
3. Spring MVC
|
||||
4. Spring batch
|
||||
5. Spring session
|
||||
6. ......
|
||||
|
||||
|
||||
以上都是spring framwork的一部分。spring framwork包含以上部分。
|
||||
|
||||
spring boot 是高层框架,底层是spring framwork。 可以用来整合Spring的整个技术栈,防止出现配置地狱。
|
||||
|
||||
### Spring boot的优势
|
||||
1. 创建独立应用。Spring boot 能够快速创建出生产级别的应用。
|
||||
2. 内嵌web服务器
|
||||
3. 创建自动依赖 ,简化构建配置。
|
||||
4. 无代码生成/无编写XML
|
||||
|
||||
|
||||
### Spring5框架结构
|
||||
|
||||
|
||||

|
||||
|
||||
|
||||
## 2 Spring boot的背景
|
||||
|
||||
### 微服务
|
||||
1. 架构风格
|
||||
2. 小型服务,灵活拆分
|
||||
3. 自动部署
|
||||
4. 去中心化、服务治理
|
||||
|
||||
|
||||
### 分布式要解决的问题
|
||||
1. 远程调用rpc——http
|
||||
2. 服务发现——网关和注册中心
|
||||
3. 负载均衡和任务调度
|
||||
4. 服务容错——流量控制和熔断
|
||||
5. 配置管理——配置中心
|
||||
6. 服务监控
|
||||
7. 链路追踪
|
||||
8. 日志管理
|
||||
|
||||
|
||||
### 云原生要解决的问题(部署过程)
|
||||
|
||||
1. 服务自愈
|
||||
2. 弹性伸缩
|
||||
3. 服务隔离
|
||||
4. 自动化部署机制
|
||||
5. 灰度发布,逐渐替代旧版本
|
||||
6. 流量治理
|
||||
99
Spring/Springboot/2 Springboot配置.md
Normal file
99
Spring/Springboot/2 Springboot配置.md
Normal file
@@ -0,0 +1,99 @@
|
||||
## 1 创建一个springboot项目
|
||||
|
||||
1. 创建Maven工程
|
||||
2. 引入依赖pom.xml
|
||||
1. 包括`<parent>`下是springboot的标签。`dependencies`下是相关的依赖。
|
||||
|
||||
```
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.3.4.RELEASE</version>
|
||||
</parent>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
```
|
||||
3. 创建主程序
|
||||
|
||||
```
|
||||
/**
|
||||
* 主程序类
|
||||
* @SpringBootApplication:这是一个SpringBoot应用
|
||||
*/
|
||||
@SpringBootApplication
|
||||
public class MainApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(MainApplication.class,args);
|
||||
}
|
||||
}
|
||||
```
|
||||
4. 编写具体业务
|
||||
|
||||
```
|
||||
@RestController
|
||||
public class HelloController {
|
||||
|
||||
|
||||
@RequestMapping("/hello")
|
||||
public String handle01(){
|
||||
return "Hello, Spring Boot 2!";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
```
|
||||
5. 运行测试
|
||||
|
||||
6. 简化配置 application.properties
|
||||
```
|
||||
server.port=8888
|
||||
```
|
||||
7. 简化部署
|
||||
1. 把项目打包成jar包,直接在目标服务器程序执行即可。
|
||||
```
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
```
|
||||
|
||||
|
||||
## 2 工程结构
|
||||
1. 主程序Main.java
|
||||
2. 业务程序Controller.java
|
||||
3. maven依赖pom.xml
|
||||
4. 配置Springboot项目application.properties是Spring的集中配置中心,包括项目相关的所有配置。
|
||||
|
||||
|
||||
## 3 依赖管理
|
||||
|
||||
1. mypom.xml
|
||||
2. parent -- spring-boot-starter-parent
|
||||
3. parent -- spring-boot-dependencies
|
||||
|
||||
1. 几乎声明了所有的版本,查看Spring-boot-dependencies中的版本。可以自定义properties标签,修改版本号。
|
||||
2. stater场景启动器。自动引入相关的所有依赖。可以自定义场景启动器,所有场景启动器最基本的以来。spring-boot-starter。引入依赖一部分可以不写版本号。引入非版本仲裁的版本号,必须要写。
|
||||
|
||||
|
||||
## 4 自动配置
|
||||
|
||||
1. 自动配好了SpringMVC
|
||||
1. 引入了SpringMVC全套组件
|
||||
2. 自动配好了SpringMVC常用功能。字符编码问题、多文件上传问题
|
||||
2. 默认程序结构
|
||||
1. 主程序所在包及其所有子包里的文件和组件都能被扫描到。无需配置包扫描
|
||||
2. 可以修改SpringbootApplication注解参数中的扫描路径。或者ComponentScan注解。
|
||||
3. .properties中的文件是绑定到具体的Java类的。这些类会在容器中创建指定的对象。
|
||||
4. 按需加载所有的自动配置,自动配置都在spring-boot-autoconfigure包中
|
||||
68
Spring/Springboot/3 Springboot底层注解.md
Normal file
68
Spring/Springboot/3 Springboot底层注解.md
Normal file
@@ -0,0 +1,68 @@
|
||||
## 注解说明
|
||||
|
||||
|
||||
### @Configuration&@Bean
|
||||
1. 配置类本身也是组件,相当于将组件注册到Spring当中。即把类的对象交给Spring管理。
|
||||
2. proxybeanMethods:代理bean方法。可以解决组件间的依赖问题。如果为false,Springboot不会检查配置类中组件间的依赖,对于依赖的其他对象直接创建新的对象。true的时候每次运行都会检查配置中组件间的依赖,不会创建新的对象。
|
||||
1. full(proxyBeanMehtods=true)
|
||||
2. lite(proxyBeanMethods=false)
|
||||
### @Bean
|
||||
1. 配置类实用@Bean标注方法上给容器注册组件,默认也是单实例。id默认为方法名。可以通过参数指定
|
||||
2. 外部类可以从Spring的容器中取出在Configuration类中注册的实例。而且都是单实例对象。
|
||||
|
||||
@Component @Controller @Service @Repository 都是以前的用法
|
||||
|
||||
@ComponetScan
|
||||
|
||||
|
||||
### @Import
|
||||
|
||||
1. 将指定的组件导入到组件。给容器中自动创建指定类型的无参构造的组件。
|
||||
2. 默认组件的名字是全类名。即包括包和类的名字。
|
||||
|
||||
|
||||
### @conditional
|
||||
1. 条件装配。满足Conditional指定的条件,则进行组件注入。
|
||||
2. 这里的条件可以是多种形式
|
||||
|
||||
@ConditionalOnBean(name="bean")当容器中存在指定名称的容器的时候,才会进行注册。
|
||||
|
||||
```
|
||||
@ConditionalOnBean(name="")
|
||||
|
||||
|
||||
```
|
||||
|
||||
### @ImportResource
|
||||
|
||||
1. 在一个配置类中,导入xml中的配置文件。
|
||||
|
||||
```
|
||||
@ImportResource(classpath:"hello.xml")
|
||||
```
|
||||
|
||||
### @ConfigurationProperties
|
||||
1. 只有在容器中的组件,才会有Springboot的强大功能。
|
||||
2. 从配置文件中自动加载,进行属性配置,然后使用Componet注册
|
||||
```
|
||||
@Component
|
||||
@ConfigurationProperties(prefix="mycar",)
|
||||
class Car(){
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
### @EnableConfigurationProperties
|
||||
|
||||
1. 在配置类上开启属性配置功能。开启car的属性配置功能
|
||||
2. 该中方法对配置类进行修改然后装配。不需要修改类本身的代码。
|
||||
```
|
||||
@EnableConfigurationProperties(Car.class)
|
||||
class MyConfig{
|
||||
|
||||
}
|
||||
```
|
||||
### @Autowired
|
||||
|
||||
1. 容器中的自动注入。
|
||||
|
||||
12
Spring/Springboot/Springboot自动配置原理.md
Normal file
12
Spring/Springboot/Springboot自动配置原理.md
Normal file
@@ -0,0 +1,12 @@
|
||||
## 自动配置类
|
||||
|
||||
### SpringBootApplication注解的详细解释
|
||||
```
|
||||
@SpringBootApplication ==>
|
||||
@SpringBootConfiguration //本身是一个配置类@Configuration,利用容器中的东西完成业务逻辑
|
||||
@EnableAutoConfiguration
|
||||
@AutoConfigurationPackage
|
||||
@Import(AutoConfigurationPackages.Register.class)利用register,将指定的包下的所有组件注册到容器中。所以默认包路径是Main程序所在的包。
|
||||
@Import(AutoConfigurationSelector.class)获取所有导入到容器中的配置类。利用Spring工厂加载器,从spring-boot-autoconfigure./META-INF/spring-factories中加载文件。Springboot一启动就要加载的所有配置类。
|
||||
@ComponentScan //包扫描的范围
|
||||
```
|
||||
BIN
Spring/Springboot/image/2022-07-04-10-30-39.png
Normal file
BIN
Spring/Springboot/image/2022-07-04-10-30-39.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 92 KiB |
0
Spring/Springframework/SpringFramework简介.md
Normal file
0
Spring/Springframework/SpringFramework简介.md
Normal file
Reference in New Issue
Block a user