Spring boot 的 properties 属性值配置 application.properties 与 自定义properties
- 配置属性值
application.properties 文件直接配置:com.ieen.super.name="MDD"
自定义properties文件配置:src/main/resources/conf/boot.properties
com.ieen.boot.name="123"
com.ieen.boot.value="456" - 调用方法
@Value 注解调用application.properties属性值:@Value("${com.ieen.super.name}")
private String name;@Value注解调用自定义properties属性值:
@PropertySource("classpath:conf/boot.properties")
public class Main{
@Value("${com.ieen.boot.name}")
private String bootName;
}注:@PropertySource 注解引入自定义properties从1.5以后才开始的
// value 为自定义配置
// ignoreResourceNotFound 默认false,文件不存在报错
// encoding 设置编码
// name 为Resource对象的beanname
@PropertySource(value = { "classpath:boot.properties",
"classpath:conf/boot.properties" }, ignoreResourceNotFound = false, encoding = "UTF-8", name = "boot-custom.properties")@ConfigurationProperties 配置properties属性对象:
// spring boot 1.5以前的配置
//@ConfigurationProperties(prefix = "com.ieen.boot",locations = "classpath:conf/boot.properties")
@ConfigurationProperties(prefix = "com.ieen.boot")
// 若是自定义properties则加上
@PropertySource(value = "classpath:conf/boot.properties", encoding = "UTF-8")
@Component
public class BootPropertiesBean {
private String name;
private String value;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}@Autowired
private BootPropertiesBean bean;
Spring boot 的 properties 属性值配置 application.properties 与 自定义properties的更多相关文章
- 初识spring boot maven管理--属性文件配置
在使用springboot的时候可以使用属性文件配置对属性值进行动态配置,官方文档原文如下: Spring Boot uses a very particular PropertySource ord ...
- spring boot 教程(三)配置详解
在大部分情况下,我们不需要做太多的配置就能够让spring boot正常运行.在一些特殊的情况下,我们需要做修改一些配置,或者需要有自己的配置属性. Spring Boot 支持多种外部配置方式 这些 ...
- Spring Boot 启动(二) 配置详解
Spring Boot 启动(二) 配置详解 Spring 系列目录(https://www.cnblogs.com/binarylei/p/10198698.html) Spring Boot 配置 ...
- Spring Boot项目简单上手+swagger配置+项目发布(可能是史上最详细的)
Spring Boot项目简单上手+swagger配置 1.项目实践 项目结构图 项目整体分为四部分:1.source code 2.sql-mapper 3.application.properti ...
- Spring boot集成Swagger2,并配置多个扫描路径,添加swagger-ui-layer
Spring boot集成Swagger,并配置多个扫描路径 1:认识Swagger Swagger 是一个规范和完整的框架,用于生成.描述.调用和可视化 RESTful 风格的 Web 服务.总体目 ...
- Spring boot集成Swagger,并配置多个扫描路径
Spring boot集成Swagger,并配置多个扫描路径 1:认识Swagger Swagger 是一个规范和完整的框架,用于生成.描述.调用和可视化 RESTful 风格的 Web 服务.总体目 ...
- spring boot不同环境读取不同配置
具体做法: 不同环境的配置设置一个配置文件,例如:dev环境下的配置配置在application-dev.properties中:prod环境下的配置配置在application-prod.prope ...
- spring boot 规范json返回值
spring boot 规范json返回值 spring boot 接口返回配置 @ResponseBody ,则返回自定义的对象,解析成json. 但是,部分字段能友好的展示出来.如 Date,Lo ...
- Spring Boot应用的后台运行配置
酱油一篇,整理一下关于Spring Boot后台运行的一些配置方式.在介绍后台运行配置之前,我们先回顾一下Spring Boot应用的几种运行方式: 运行Spring Boot的应用主类 使用Mave ...
随机推荐
- matlab中特殊符号如希腊字符
使用legend 'Best' 图标标识放在图框内不与图冲突的最佳位置'BestOutside' 图标标识放在图框外使用最小空间的最佳位置 legend('sin','cos','location', ...
- MT4 取K线
目标:动态获取最新K线并通过DLL发送出去,symbols和periods可配置. //+------------------------------------------------------- ...
- leetcode 764.Largest Plus Sign
根据题意的话就是在非0的地方开始寻找上下左右分别能够走到的最大步长的. 那么使用暴力的方法竟然leetcode还是给过了. class Solution { public: int orderOfLa ...
- 非root用户安装python3
1.下载源码 wget -c https://www.python.org/ftp/python/3.7.1/Python-3.7.1.tgz 解压: tar xzf Python-3.7.1.tgz ...
- sql执行内部操作期间检测到不一致性解决方案
解决方法:重启下SQL服务,把下面脚本运行即可.运行后,坏掉的数据库可能会丢失. --mydb 为坏了的数据库名--mytable 为坏了的据库表--master 这里不需要更改 use mydb ...
- ubuntu下安装无界面浏览器
ubuntu下安装PhantomJS 1.下载: 32位:wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-li ...
- camelcase-hankerrank
int camelcase(string s) { int cnt=0; int a; for(int i=0;i<s.size();i++) { a=s[i]; if(65<=a& ...
- git忽视上传规则文件 .gitignore
语法 语法 作用 例子 "/" 忽略根目录下的文件 /data "*" 忽略所有文件 *.txt => 1.txt,2.txt... "?&qu ...
- 初学git,初始化库|添加文件ignore|提交方法
1.初始化git仓库: 进入任意目录,右键选择:Git Bash Here,输入命令:git status 查看当前git库的状态. 如要排除文件,在库根目录下创建.gitignore文件(新建文件改 ...
- NodeJS 学习笔记
1. NodeJs的事件模型被称为非阻塞式IO或者事件驱动IO 2. Node.js 几乎每一个 API 都是支持回调函数的. 3. Node.js 基本上所有的事件机制都是用设计模式中观察者模式实现 ...