Spring Boot 笔记

springBoot 注解示意图:

复制代码
@SpringBootApplication
    →@EnableAutoConfiguration
    →导入组件类@Import({AutoConfigurationImportSelector.class})
    →调用方法 selectImports()
    →1.找文件 spring-boot-autoconfigure/MEETA-INF/spring.factories
    →2.在文件中查找 EnableAutoConfiguration为key的集合,根据maven依赖导入jar包来筛选配置类

ImportSelector 导入组件

定义一个组件

java 复制代码
//1.Import 注解导入组件    UserConfig
@Configuration
@Import(People.class)
public class UserConfig{
}

//2. 实现 ImportSleector 重写 slctImports
public class People implements ImportSleector{
    @Override
    public String[] slctImports(AnnotationMtadata annotationMtadata ){
        // 自动注入的server  
        return new String[]{com.csdn.service.HrmSrviceImpl}
    }
}
//3.controller

public class UserController{

    //自动注入
    @Autowired
    private HrmSrviceImpl hrmSrviceImpl;

    pulbic String getUserAll(){
        hrmSrviceImpl.tstSeervice();
        return "index";
    }

}

//3.1 HrmSrviceImpl .tstSeervice
public class HrmSrviceImpl{
    public void tstSeervice(){
        //
    }
} 

ImportBeanDefinitionRegistrar 导入组件

java 复制代码
//1. 实现 ImportBeanDefinitionRegistrar 
public class UserDefinitionRegistrar implements ImportBeanDefinitionRegistrar{
    @Override
    public void registerBeanDefinitions(***){
        //***
    }
}



// 2. import 注解导入

@Configuration
@Import(UserDefinitionRegistrar .class)
public class People {
    
}

Condition 导入组件

java 复制代码
//1.@ Conditional 条件注解 实现 Condition  导入bean 条件判断

public class TestCondition implements Condition{
    @Override
    public boolean matches(){
    
        if(ctx.geetBeanrFactory().containsBean("user")){
            retrun true;
        }else{
            retrun false;
        }
    }
}

生命周期

复制代码
----------正在对容器进行处理----容器后处理器-------------------
------初始化之前执行后处理postProcessBeforeInitialization----
------初始化之后执行后处理postProcessAfterInitialization----
--------调用了有参构造器------
-------BeanNameAware--setBeanName--------
---------setApplicationContext--------
------初始化之前执行后处理postProcessBeforeInitialization---
------InitializingBean---afterPropertiesSet初始化-------
---------init-模拟初始化方法-------
------初始化之后执行后处理postProcessAfterInitialization----
-----------创建spring 容器创建完成--------------

------DisposableBean---destroy销毁时执行的方法-------
---------close模拟销毁spring容器方法-------
相关推荐
夜郎king4 小时前
Shapefile 一键生成 GeoServer 样式:GeoTools + Spring Boot 实现 YSLD 自动生成器
spring boot·gis·geotools·ysld
她的男孩5 小时前
Spring Boot 接 Flowable:请假单要同时走财务和行政,包容分支和默认分支怎么配
java·spring boot·工作流引擎
CoderYanger7 小时前
Java EE 进阶:11. SpringBoot 统一功能处理(第四弹):@ControllerAdvice 源码分析+案例代码
java·数据库·spring boot·后端·spring·java-ee·mybatis
CoderYanger13 小时前
Java EE 进阶:11. SpringBoot 统一功能处理(第三弹):统一数据返回格式+统一异常处理
java·数据库·spring boot·后端·spring·java-ee·mybatis
软件技术NINI14 小时前
基于SpringBoot的滑雪场设备租赁系统
java·spring boot·后端
有个傻瓜1 天前
分页 total 对不上、列表还少几条:MyBatis-Plus 一对多 LEFT JOIN 分页错乱复盘与四种写法实测
spring boot·sql优化·mybatis-plus·分页查询·踩坑复盘
千寻技术帮1 天前
微信小程序+Spring Boot 烘焙商城系统(附完整源码+数据库+部署文档)50053
数据库·spring boot·微信小程序·烘焙商城
CoderYanger2 天前
Java EE 进阶:11. SpringBoot 统一功能处理(第二弹):DispatcherServlet 源码分析+适配器模式
java·数据库·hive·spring boot·面试·java-ee·mybatis
她的男孩2 天前
状态默认填了 DRAFT,同步后却变成 '''DRAFT'':Forge Admin 清洗 PG 的 COLUMN_DEFAULT
spring boot·低代码·postgresql
考虑考虑2 天前
记一次@Async生产事故
spring boot·后端·spring