SpringBoot学习---自动装配原理、主启动类运行机制、yaml、JSR303校验

本文详细探讨了SpringBoot的自动装配原理,包括@SpringBootConfiguration和@EnableAutoConfiguration的作用,以及主启动类的运行机制。同时,介绍了如何在application.properties或yaml中配置项目端口。此外,还讲解了JSR303验证标准及其应用场景。
摘要由CSDN通过智能技术生成

修改项目端口号

在application.properties配置文件中输入server.post=8081 重启项目即可修改端口号。

原理初探

在pom.xml中

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.3.4.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

点击进入spring-boot-starter-parent底层,ctrl+鼠标左键

  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-dependencies</artifactId>
   <version>2.3.4.RELEASE</version>
  </parent>

spring-boot-dependencies存储核心依赖,在父工程中
在写和引入Springboot的时候,不需要引入版本,在工程已经全部导入

启动器

    <!--启动器-->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
    </dependency>

启动器:Springboot启动场景
它会将所有的功能场景,全部都变成启动器
如果需要使用什么功能,直接找到启动器即可

主程序

package com.ty.study;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

//标注这个项目是一个Springboot的项目
@SpringBootApplication
public class StudyApplication {
//将springboot启动,通过反射
public static void main(String[] args) {
SpringApplication.run(StudyApplication.class, args);
}
}

点击SpringBootApplication进入底层,查看
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@SpringBootConfiguration //核心
@EnableAutoConfiguration
//核心
@ComponentScan( //扫描下面的包 配置扫描
excludeFilters = {@Filter(
type = FilterType.CUSTOM,
classes = {TypeExcludeFilter.class}
), @Filter(
type = FilterType.CUSTOM,
classes = {Au

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值