springboot

springboot

约定优于配置,快速使用spring的一种方式>>>遵循约定开发
springboot的两大核心,起步依赖,自动配置

使用springboot

注意 :创建springboot项目的时候
在这里插入图片描述

这里要选择一个稳定的版本

springboot启动的时候,时候会扫描启动类所在的包及其子包,所以@Controller等要注入ioc的bean的类要写在启动类的所在包的子包下面
在这里插入图片描述

springboot热部署
引入依赖
在这里插入图片描述

修改idea配置
在这里插入图片描述
Ctrl+Shift+Alt+/ 修改设置
在这里插入图片描述
配置文件注入
1.类上面加注解@ConfigurationProperties(要有set方法)
2.属性上面加@Value (不需要set,反射实现),无法注入map,yml行内式写法

配置文件优先级
在这里插入图片描述
后加载的会覆盖先加载的
springboot默认只会加载application开头的配置文件,如果需要加载自定义的配置文件则需要使用@PropertySource在这里插入图片描述

依赖管理和自动配置

@SpringBootApplication→@SpringBootConfiguration→@Configuration表示项目启动类是个配置类,可以被扫描到
@EnableAutoConfiguration→@AutoConfigurationPackage→@Import(AutoConfigurationPackage.Registrar.class)
在Register类中registerBeanDefinitions在SpringBoot启动的时候会自动被调用
在这里插入图片描述
new PackageImports(metadata).getPackageNames().toArray(new String[0])参数获得被这个注解标记的类的路径
在这里插入图片描述
拿到这个路径后会扫描路径下的包及其子包,然后在@ComponentScan注解下将该路径扫描到的组件注入到容器当中

@EnableAutoConfiguration→@Import(AutoConfigurationImportSelector.Class)

这个方法会导入SpringBoot的组件
从getAutoConfigurationEntry方法进去
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里获得需要自动加载的配置类
在这里插入图片描述
这些类有一些加载条件
在这里插入图片描述
在这里插入图片描述

然后回到getAutoConfigurationEntry方法
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

org.springframework.boot.autoconfigure.admin.SpringApplicationAdminJmxAutoConfiguration=
org.springframework.boot.autoconfigure.admin.SpringApplicationAdminJmxAutoConfiguration.AutoConfigureAfter=org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration
org.springframework.boot.autoconfigure.amqp.RabbitAnnotationDrivenConfiguration=
org.springframework.boot.autoconfigure.amqp.RabbitAnnotationDrivenConfiguration.ConditionalOnClass=org.springframework.amqp.rabbit.annotation.EnableRabbit
org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration=
org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration$MessagingTemplateConfiguration=
org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration$MessagingTemplateConfiguration.ConditionalOnClass=org.springframework.amqp.rabbit.core.RabbitMessagingTemplate
org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration.ConditionalOnClass=com.rabbitmq.client.Channel,org.springframework.amqp.rabbit.core.RabbitTemplate
org.springframework.boot.autoconfigure.aop.AopAutoConfiguration$AspectJAutoProxyingConfiguration=
org.springframework.boot.autoconfigure.aop.AopAutoConfiguration$AspectJAutoProxyingConfiguration.ConditionalOnClass=org.aspectj.weaver.Advice
org.springframework.boot.autoconfigure.batch.BatchAutoConfiguration=
org.springframework.boot.autoconfigure.batch.BatchAutoConfiguration$DataSourceInitializerConfiguration=
org.springframework.boot.autoconfigure.batch.BatchAutoConfiguration$DataSourceInitializerConfiguration.ConditionalOnBean=javax.sql.DataSource
org.springframework.boot.autoconfigure.batch.BatchAutoConfiguration$DataSourceInitializerConfiguration.ConditionalOnClass=org.springframework.jdbc.datasource.init.DatabasePopulator
org.springframework.boot.autoconfigure.batch.BatchAutoConfiguration.AutoConfigureAfter=org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration
org.springframework.boot.autoconfigure.batch.BatchAutoConfiguration.ConditionalOnBean=org.springframework.batch.core.launch.JobLauncher
org.springframework.boot.autoconfigure.batch.BatchAutoConfiguration.ConditionalOnClass=javax.sql.DataSource,org.springframework.batch.core.launch.JobLauncher
org.springframework.boot.autoconfigure.batch.BatchConfigurerConfiguration=
or

这里配置了所有支持自动配置类的条件然后封装成AutoConfigurationMetadata

在filter方法中会对这些条件进行过滤
在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值