springboot学习

SpringBoot入门

视频学习地址:url:https://www.bilibili.com/video/BV1Et411Y7tQ?p=1
链接: link
1,pom文件

//该文件作为版本仲裁中心,对于我们未来使用的各种场景下的各个jar包的版本进行了约束,当我们在没有显示的声明我们的版本号的时候,就会使用springBoot为我们默认的版本号

 <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.3.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
  
实际的版本声明在该pom文件中声明
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-dependencies</artifactId>
    <version>2.3.3.RELEASE</version>
  </parent>

2,spirng-boot-starter-*启动器的含义
eg:spring-boot-starter-web

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
以下为spring-boot-web中所添加的依赖,有了这些依赖,我们便不再需要使用本地的tomcat服务器,因为在我们的项目中将会引入我们所需要的tomcat依赖项(这大概也就是通常所说的springboot内置了Tomcat服务器的原因吧?)
当我们在不同的场景下,我们只需要导入对应的启动器就可以了,因为不同的启动器中已经有了我们所需要的依赖。
 <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-json</artifactId>
      <version>2.3.3.RELEASE</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-tomcat</artifactId>
      <version>2.3.3.RELEASE</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-web</artifactId>
      <version>5.2.8.RELEASE</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-webmvc</artifactId>
      <version>5.2.8.RELEASE</version>
      <scope>compile</scope>
    </dependency>
  </dependencies>

3@springBootApplicaton注解详解
springBootApplicaton是一个复合注解,其中的两个核心注解如下

	@SpringBootConfiguration
	@EnableAutoConfiguration
  1. @SpringBootConfiguration

    • @Configuration将其标注为一个配置类
    • @Component将其放置在spring容器当中
  2. @EnableAutoConfiguration(组合注解)
    @AutoConfigurationPackage
    @Import({AutoConfigurationImportSelector.class})

    @AutoConfigurationPackage

    • @Import({Registrar.class})在容器中添加了一个组件,而该组件的作用就是能够将带有@springbootApplication注解的包名获取到,并且能够将该包下的所有类进行扫描,对于需要交给spring管理的组件,会将其加入到容器当中
      在这里插入图片描述通过该图片可以看出,对于带有@SpringBootApplicaion注解的类的所在包已经获取到了。
      2 . @Import({AutoConfigurationImportSelector.class})(向容器中添加一些组件)如下展示了加载spring-boot-configure中的spring-factorys中的指定资源的核心逻辑。
      在这里插入图片描述 springboot自动配置的核心
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值