springboot大揭秘

Springboot 大揭秘web

 

springmvc ---> 相应web开发配置 --- >applicationcontext.xml --->-bean相关配置spring

                                 springmvc.xml --->component-scan :包的路径扫描 ; jsp的解析器 prefix 前缀   suffix后缀的配置spring-mvc

                                 web.xml--->dispatcherservlet:springmvc.xml配置文件的引入springboot

这只是原架构开发web项目中须要配置的文件的一小部分   配置文件很繁杂  mybatis

 

Springboot:方便帮你基于spring搭建web工程,以及相应的开发;架构

Springboot是基于framework之上搭建的;mvc

 

Springboot是怎么自动配置的呢?app

Springboot的启动内有一个@springbootapplication的注解;jsp

@springbootapplication它是个组合注解它主要包含@springbootconfiguration @componentscan @enableautoconfigurationspring-boot

 

额外说下:

Spring源码设计者它们是怎么来操做和管理包含了注解的类呢?

如:@controller   @service  @repository @component  咱们都知道,若是含有这些注解,它的意思都是交由ioc容器管理;

Spring源码设计者,ioc容器: 都是先进行包路径的扫描;而后解析每一个路径下的各种,而后利用反射的方式进行找到其注解(如:是否含义@controller),而后建立其对象,而后在用map存储起来,如map.put(’usercontollerr’,new usercontroller());外界就能够经过context.getBean(‘usercontroller’)就能够取到这个对象; 这也是ioc容器管理对象的实现过程;

 

@ springbootconfiguration 它是个组合注解 它包含 @configuration ;而@configuration它又包含@component; @component的意思都是将该类交由ioc容器管理;@configuration额外的一个做用就是让当前的bean成为一个配置bean(就是让当前的类成为一个配置类)

 

在原来web开发中  咱们都会见一个controller类并加上@controller注解  再在spring-mvc.properties里配置<componet-scan> 及其路径 来进行扫描其路径下所包含注解的类 ;

 

而springboot怎么实现含有注解类的扫描呢?

 

@componentscan 就是至关于<componet-scan> ;@componentscan里加上扫描路径;

 

@componentscan+@springbootconfiguration:一结合起来,就能找 自动装配,咱们用户自定义的类 交给ioc容器进行管理

@componentscan扫描的路径就是根路径

 

假如说程序中默认用到的配置,用到的又不是用户自定义,系统自带的;如

<bean name=”dataSource” class=”xxxx.xxxx.yyy.DataSource”/> 

这个就要用到@Enableautoconfiguration

在@Enableautoconfiguration 里导入了AutoconfigurationImportseletor.class这个类,而@enableautoconfiguration就是经过这个类把系统自己的配置加载进去 扫描的路径是在在meta-inf/spring.factories中

 

因此:

      @Enablautoconfuguration让spring自动化配置机制 注重系统自己配置的自动化加载配置

      @springbootconfiguration @componentscan注重用户自定义配置的自动加载配置

 

 

 

 

Springboot内置容器 Tomcat jetty

 

Tomcat启动类属于系统内部配置    那么配置就会在meta-inf/spring.factories中;交给@Enablautoconfuguration托管  经过工厂模式设计 

 

 

Springapplicatin.run()  执行时  都作了哪些操做

  1. 建立springapplication应用
  2. Run方法的启动:执行如下操做

 

获取Spring context上下文  ioc容器; bean的装配

Listeners监听器启动  filter 过滤器启动  监听器/过滤器类的全路径 经过@Eableautoconfiguration获取 配置确定在meta-inf/spring.factories中

图标设置 日志打印  时间打印

Web servlet 的判断

Web容器的启动

 

Springboot Starter引入就是把原来的

1.引入jar

2.配置文件

3.配置须要使用的类

4.测试代码

都封装在了一个starter中

在springboot配置文件里 直接引入某个starter就能够完成你想要的功能

若是你想使用mybatis 你直接引用spring-boot-starter-mybatis就能够啦