Java Springboot的目的你知道吗
作者:夏来梦栀子 时间:2022-12-20 14:16:24
Spring-boot目的
Spring是为了解决企业应用开发的复杂性而创建的,简化开发
Spring如何简化开发
1.基于POJO的轻量级和最小侵入性编程
2.通过IOC,依赖注入(DI)和面向接口实现松耦合
3.基于(AOP)和惯例进行声明式编程
4.基于切面和模板减少样式代码
微服务
第一个spring-boot程序
官方提供了一个快速生成的网站!idea集成了这个网站
1可以在官网下载后,导入idea开发(官网)
2直接使用idea创建一个springboot项目(一般直接在idea创建)
自动配置原理
自动配置:pom.xml
spring-boot-dependencies:核心依赖在父工程中
我们在写或者引入一些springboot依赖的时候,不需要指定版本就是因为有这些版本仓库
启动器
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
启动器:说白了就是SpringBoot的场景启动器
比如spring-boot-starter,他就会帮我们自动导入web环境所有依赖
springboot会将所有的功能场景,都变成一个个的启动器
我们要使用什么功能,就只需要找到对应的启动器就可以了start
主程序
//标注这个类是一个springboot应用
@SpringBootApplication
public class SpringBoot01HelloworldApplication {
public static void main(String[] args) {
SpringApplication.run(SpringBoot01HelloworldApplication.class, args);
}
}
@SpringBootConfigurationspringboot的配置
往下
@configuationspring配置类
往下
@Component:说明是一个spring组件
@EnableAutoConfiguration:自动配置
@@AutoConfigurationPackage:自动配置包
@Import(@AutoConfigurationPackage.Registrar.class):自动配置包注册
@Import({AutoConfigurationImportSelector.class}):自动导入选择(组件)
List<String> configurations = this.getCandidateConfigurations(annotationMetadata, attributes);
获得所有的配置
获取候选的配置
protected List<String> getCandidateConfigurations(AnnotationMetadata metadata, AnnotationAttributes attributes) {
List<String> configurations = SpringFactoriesLoader.loadFactoryNames(this.getSpringFactoriesLoaderFactoryClass(), this.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;
}
META-INF/spring.factories自动配置的核心文件
Properties properties = PropertiesLoaderUtils.loadProperties(resource); 所有资源加载到配置类中
结论:
springboot所有自动配置都是在启动的时候扫描并加载spring-factories所有的自动配置类都在里面,但是不一定生效,要判断条件是否成立,要判断是否成立,只要导入对应的start,就有对应的启动器,有了启动器,我们自动装配就会生效,然后就2配置成功了
1.springboot在启动的时候,从类的路径下/META-INF/spring.factories获取指定的值;
2.将这些自动配置的类导入容器 自动配置类就会生效,帮我们进行自动配置
3.一起我们需要自动配置的东西,现在springboot帮我们做了
4.整合javaEE,解决方案和自动配置的东西都在spring-boot-autoconfigure-2.3.7.RELEASE.jar
5.他会把所有需要导入的组件,以类名方式返回,这些组件就会被添加到容器;
6、容器中也会存在非常多的xxxAutoConfiguration的文件(@Bean),就是这些容器中导入了这个场景需要的所有组件并自动配置,@Configuration,javaConfig!
7.有了自动配置类,免去了我们手动编写配置文件的工作
SpringApplication.run(SpringBoot01HelloworldApplication.class, args);
SpringApplication加载主类
这个类主要做了以下四件事情
1.判断应用的类型的普通的项目还是web项目
2.查找并加载所有可用初始化器,设置到initializers属性中
3.找出所有的应用程序 * ,设置到listeners属性中
4.推断并设置main方法的定义类,找到运行的主类
javaConfig @Configuration @Bean
Docker:进程
tializers属性中
3.找出所有的应用程序 * ,设置到listeners属性中
4.推断并设置main方法的定义类,找到运行的主类
javaConfig @Configuration @Bean
Docker:进程
来源:https://blog.csdn.net/qq_52329552/article/details/120208834
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Flutter 如何封装文本输入框组件
Android自定义TextView实现drawableLeft内容居中
![](https://img.aspxhome.com/file/2023/2/122092_0s.png)
C#中WPF内存回收与释放LierdaCracker的实现
Java8使用stream实现list中对象属性的合并(去重并求和)
![](https://img.aspxhome.com/file/2023/9/62379_0s.png)
详解Java中的Lambda表达式
如何使用C#代码创建快捷方式文件详解
![](https://img.aspxhome.com/file/2023/1/119561_0s.jpg)
Flutter深色模式适配的实现
![](https://img.aspxhome.com/file/2023/0/138710_0s.jpg)
C#实现农历日历的方法
java使用dom4j操作xml示例代码
Spring Boot mybatis-config 和 log4j 输出sql 日志的方式
![](https://img.aspxhome.com/file/2023/6/101756_0s.png)
基于Android实现点击某个按钮让菜单选项从按钮周围指定位置弹出
![](https://img.aspxhome.com/file/2023/3/114283_0s.png)
使用EasyPoi轻松导入导出Excel文档的方法示例
![](https://img.aspxhome.com/file/2023/8/92638_0s.png)
Java集合去重导致的线上问题
![](https://img.aspxhome.com/file/2023/7/65627_0s.webp)
Maven生命周期和及插件原理用法详解
![](https://img.aspxhome.com/file/2023/2/75442_0s.png)
详细解读java同步之synchronized解析
C#实现缩放和剪裁图片的方法示例
Android开发之开关按钮控件ToggleButton简单用法示例
![](https://img.aspxhome.com/file/2023/1/137381_0s.gif)
利用java反射机制实现自动调用类的简单方法
Java JVM程序指令码实例解析
![](https://img.aspxhome.com/file/2023/6/81356_0s.png)
springboot2.0如何通过fastdfs实现文件分布式上传
![](https://img.aspxhome.com/file/2023/7/71917_0s.png)