SpringBoot 读取配置文件属性值
来源:互联网 发布:数据魔方架构 编辑:程序博客网 时间:2024/06/05 07:13
SpringBoot有两种配置文件properties和yml配置文件,但读取的方式都是一样的。主要有以下的两种方式,以yml文件作为讲解:
yml文件:
auth: authUrl: https://auth.test.com/a/ cookieName: auth.session.id version: 1.0
1、使用@Value注解将配置文件的属性注入到类属性中
@Value("${auth.authUrl}") private String authUrl; @Value("${auth.cookieName}") private String cookieName; @Value("${auth.redisVersion}") private String redisVersion;
2、使用@ConfigurationProperties,它可以把同类的配置信息自动封装成实体类,在需要使用配置文件属性时,只需要将封装的实体类注入到使用出就可以获取到属性的信息。
@Component@ConfigurationProperties(prefix="auth")public class AuthSettings { private String authUrl; private String cookieName; private String redisVersion; public String getAuthUrl() { return authUrl; } public void setAuthUrl(String authUrl) { this.authUrl = authUrl; } public String getCookieName() { return cookieName; } public void setCookieName(String cookieName) { this.cookieName = cookieName; } public String getRedisVersion() { return redisVersion; } public void setRedisVersion(String redisVersion) { this.redisVersion = redisVersion; }}
阅读全文
0 0
- SpringBoot 读取配置文件属性值
- SpringBoot读取配置文件乱码
- springboot读取自定义配置文件
- SpringBoot配置文件读取
- SpringBoot读取配置文件
- SpringBoot 读取自定义配置文件
- springboot读取配置文件
- springboot实战之读取配置文件
- SpringBoot(三):SpringBoot 属性配置文件详解
- 四、SpringBoot属性配置文件详解
- SpringBoot之属性配置文件详解
- Springboot 之 自定义配置文件及读取配置文件
- SpringBoot 读取配置文件及profiles切换配置文件
- Springboot 之 自定义配置文件及读取配置文件
- Springboot 之 自定义配置文件及读取配置文件
- Springboot 之 自定义配置文件及读取配置文件
- Springboot 之 自定义配置文件及读取配置文件
- Springboot 之 自定义配置文件及读取配置文件
- struct iovec 结构体定义与使用
- 观察者模式
- 兼容ie8 rgba()用法
- 大数据环境下该如何优雅地设计数据分层
- 3个常用基于Linux系统命令行WEB网站浏览工具(w3m/Links/Lynx)
- SpringBoot 读取配置文件属性值
- 欢迎使用CSDN-markdown编辑器
- Kinetis单片机——引脚配置
- 算法思想 -- 贪心算法(1) -- 基本概念及步骤
- 欢迎使用CSDN-markdown编辑器
- windbg 脚本学习总结
- 漫谈数据仓库之基本概念总结(不断更新)
- 取消win10任务栏预览窗口的方法
- 使用SimpleAdapter显示网络图片