https://blog.youkuaiyun.com/u013777094/article/details/78580710/
使用springboot必须要java8或以上。
创建springboot项目的maven类型,必须是jar类型。
一、springboot的依赖继承

这里的spring-boot-starter-parent是干什么的呢?
其实,这里就是maven的父子工程的一个概念。在parent工程中放很多公用的依赖,子工程就可以通过maven依赖继承关系,来使用parent中的依赖。

从maven依赖可以看出,springboot集成了springmvc
二、@SpringBootApplication方式启动
启动类抽取出来,并且使用@ComponentScan进行controller的包扫描

三、springboot的启动原理
springmvc注解方式启动 内置http服务器(默认是tomcat)


四、@EnableAutoConfiguration作用

在这里启动springboot,只能访问到这个类本身的controller。因为,@EnableAutoConfiguration的扫包范围,默认在当前类里。
五、SpringApplication.run(App.class, args)的作用
它是整个程序入口,启动springboot项目。创建内置tomcat服务器,使用tomcat加载springmvc注解启动类。
六、@ComponentScan方式启动
@EnableAutoConfiguration配合上@ComponentScan使用

这个时候,controller包下的路径都可以访问到。
七、普遍形式
启动类只需要一个即可。那么,把启动类抽出来

八、@SpringBootApplication

@SpringBootApplication=@EnableAutoConfiguration+@ComponentScan
扫同级包和当前包。
本文详细解析了SpringBoot的启动原理,包括依赖继承、@SpringBootApplication的作用、内置HTTP服务器的启动过程,以及如何通过@ComponentScan和@EnableAutoConfiguration实现自动配置。
2211

被折叠的 条评论
为什么被折叠?



