SpringBoot入口注解
@SpringBootApplication:标注这个类是一个springboot应用,启动类下的所有资源被导入
-@SpringBootConfiguration
--@Configuration
---@Component
-@EnableAutoConfiguration //自动导入包
--@AutoConfigurationPackage
---@Import({Registrar.class}) //自动注册包
--@Import({AutoConfigurationImportSelector.class}) //自动导入包的核心
---AutoConfigurationImportSelector //选择了什么东西
-@Component //扫描主启动类同级的包
SpringBoot入口启动
SpringApplication类的run方法判断是普通项目还是WEB项目,如果是WEB项目就启动tomcat服务
application.yml(.ymal)和application.properts的区别
#application.yml编写方式
# 对空格的配置非常高
server:
port: 8088
# 普通的K-V
name: aaa
# 对象
student:
name: hzy
age: 18
# 行内写法
students: {name: aaa,age:18}
# 数组
pets:
1. cat
2. dog
3. pig
petss: [cat,dog,pig]
#application.properts编写方式
server.port= 8088
#键值对
name=aaa
# 对象
student.name: hzy
student.age: 18
.yml文件中可以使用${}表达示推荐使用yml方式
变量绑定.yml或者.properties文件中对象给属性复制
@ConfigurationProperties(prefix = “person”)//默认会报,不影响正常操作,把.yml中的person对象赋值给类中对应的变量
@PropertySource(value = “classpath:test.properties”)//绑定.properties配置文件
@Value("${属性名}")//给变量赋值
JSR303数据校验
@Validated //在类上方写开始数据校验
下方图片表示在属性上方添加的注解表示限制格式
下方是注解限制进行的扩展
配置文件存放位置的优先级
.properties多配置文件 #springboot的多环境配置,可以选择激活哪一个配置文件 (注意只能在application.properties中配置)
spring.profiles.active=dev //dev表示application-dev.properties文件
.yml单文件多模块配置
spring:
profiles:
active: dev
---
server:
port: 8089
spring:
profiles: dev
---
server:
port: 8090
spring:
profiles: test
在配置文件中可以通过debug: true来查看哪些自动装配类生效了,哪些没有生效