zoukankan      html  css  js  c++  java
  • Springboot入门-01

    微服务阶段

    javaSE : OOP

    Mysql: 持久化

    html+css+js+jquery+框架: 视图、框架不熟练、css不熟练。

    javaWeb: 独立开发MVC三层架构网站: 最原始

    ssm: 框架,简化了开发流程,配置也变得较为复杂。

    war: tomcat运行

    spring再简化:SpringBoot- jar: 内嵌Tomcat; 微服务架构开始!

    服务越来越多: SpringCloud 管理服务。

     

    什么是微服务?

    MVC三层架构 MVVM 微服务结构

    业务: service : UserService: ===> 每个服务都独立成一个模块

    springmvc, controller ===> 提供接口调用

    Http模式、RPC模式

    第一个SptingBoot程序

    环境:

    • jdk1.8

    • maven 3.5.3

    • IDEA

    自动配置原理

    自动配置:

    pom.xml

    • spring-boot-dependencies: 核心依赖在 父工程中

    • 在引入一些依赖时,不需要在指定版本。因为父工程已定义

       

    启动器

    • <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter</artifactId>
      </dependency>
    • 启动器:就是Springboot的启动场景(依赖)

    • spring-boot-starter-web 就会自动导入web环境所需的所有依赖

    • 要使用什么功能,只需要导入对应的 starter启动器就可以。

    主程序

    //@SpringBootApplication : 标注这个类是一个 springboot的应用
    @SpringBootApplication
    public class SpringbootApplication {
    
        public static void main(String[] args) {
            // 将springboot应用启动。主入口
            SpringApplication.run(SpringbootApplication.class, args);
        }
    }

    注解

    @SpringBootConfiguration : springboot的配置
            @Configuration : spring配置类
            @Component: 该类本身就是个组件
                
    @EnableAutoConfiguration: 自动配置
            @AutoConfigurationPackage: 自动配置包
                @Import(AutoConfigurationPackages.Registrar.class): 自动配置包`注册`
                
            @Import(AutoConfigurationImportSelector.class): 自动配置导入选择
    
    // 获取所有的配置
    List<String> configurations = getCandidateConfigurations(annotationMetadata, attributes);            
                

    获取候选的配置

    protected List<String> getCandidateConfigurations(AnnotationMetadata metadata, AnnotationAttributes attributes) {
            List<String> configurations = SpringFactoriesLoader.loadFactoryNames(getSpringFactoriesLoaderFactoryClass(),
                    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: 自动配置的核心文件

    路径在: spring-boot-autoconfigure-2.2.0.RELEASE.jar/META-INF/spring.factories 文件中

    Properties properties = PropertiesLoaderUtils.loadProperties(resource);
    所以资源加载到配置类中

    结论: spring boot所有自动配置都是在启动的时候扫描并加载,spring.factories所有的的自动配置类都在这里,但不一定生效。要判断条件是否成立,只有导入了相应的启动器,自动配置才会生效。

    1. Springboot在启动的时候从类路径下 META-INF/spring.factiries中获取 EnableAutoConfiguration指定的值。

    2. 将这些值指定的自动配置类导入到容器,自动配置类就会生效,前提必须要有对应的starter场景启动器。

    帮助我们完成自动配置工作。

    1. 整个javaEE体系的解决方案和自动配置都在 springboot-autoconfiguration的jar包中。

    2. 它将所有需要导入的组件以全类名的方式返回。这些组件会被添加到容器中。

    3. 它会给容器中导入非常多的自动配置类。格式为(xxxxAutoConfiguration),就是给容器中这个场景需要的组件,并自动配置好这些组件。

    4. 有了自动配置类,免去了手动去配置编写注入功能组件的工作。

  • 相关阅读:
    路径变量@PathVariable/请求参数@RequestParam的绑定以及@RequestBody
    JSR303后端校验详细笔记
    创建ssm项目步骤
    利用 R 绘制拟合曲线
    在 Linux 中将 Caps 根据是否为修饰键分别映射到 esc 和 Ctrl
    Master Transcription Factors and Mediator Establish Super-Enhancers at Key Cell Identity Genes
    Genomic Evidence for Complex Domestication History of the Cultivated Tomato in Latin America
    Variation Revealed by SNP Genotyping and Morphology Provides Insight into the Origin of the Tomato
    The genetic, developmental, and molecular bases of fruit size and shape variation in tomato
    微信支付jsapi
  • 原文地址:https://www.cnblogs.com/mt-blog/p/13339609.html
Copyright © 2011-2022 走看看