Spring boot 笔记
JSR 303配置属性值的数据校验
hibernate-validator



@Validated必须在主类上标注 可以校验所有子类的所有属性
@NotEmpty


加载旧配置文件
2种加载方式:

使用@PropertySource(value="classpath:family.yml")加载 src/main/resources中的yml文件

PropertySource这个只加载properties文件,默认不加载yml文件,需要创建service类并继承DefaultPropertySourceFactory



默认支持


ImportResource导入配置文件



使用SpEL表达式绑定配置项
更多spel参考官方文档
https://docs.spring.io/spring/docs/4.3.10.RELEASE/spring-framework-reference/html/expressions.html

properties 只读取逗号分隔,无法读取竖线分隔,需要定义配置类


@Configuration和@Componet注解都是依赖注入
读取配置文件时乱码设置

配置类
分割竖线



默认值31



浙公网安备 33010602011771号