Spring Boot自定义属性配置文件开启提示
前言:有时候在Sping Boot项目中需要自定义属性。又想在配置文件(*.properties)中显示提示时。
测试环境:Sping Boot2x + Maven + Lombok
准备测试的配置类:
@Data
@Configuration
@ConfigurationProperties(prefix = "animal.default")
public class Animal {
private String name;
private String type;
}
使用@ConfigurationProperties(prefix = "animal.default")
自定义一个前缀。使用默认配置文件
我们可以看到这个时候在配置文件中输入是没有关于“animal.default”的任何提示。
现在我们通过添加配置则可以让它有显示。
1. 在启动类上添加@EnableConfigurationProperties
注解。如下所示:
@SpringBootApplication
@EnableConfigurationProperties
//@EnableConfigurationProperties({Animal.class}) 可以指定类,也可以不指定
public class TestProjectApplication {
public static void main(String[] args) {
SpringApplication.run(TestProjectApplication.class,args);
}
}
2. 使用Maven工具依次执行 clean 和 package 命令。在执行命令后可以看到下图:
现在我们再去配置文件中测试会发现已经有提示功能。如下图:
Spring Boot自定义属性配置文件开启提示的更多相关文章
- spring boot / cloud (六) 开启CORS跨域访问
spring boot / cloud (六) 开启CORS跨域访问 前言 什么是CORS? Cross-origin resource sharing(跨域资源共享),是一个W3C标准,它允许你向一 ...
- Spring Boot 的配置文件application.properties
Spring Boot 中的application.properties 是一个全局的配置文件,放在src/main/resources 目录下或者类路径的/config下. 作为全局配置文件的app ...
- Spring Boot之配置文件值注入(@ConfigurationProperties)
前言:Spring Boot配置文件值的注入有两种方式,分别是 @ConfigurationProperties @Value 这里我们使用第一种 首先我们创建一个application.yml文件, ...
- Spring Boot(二) 配置文件
文章导航-readme 一.配置Spring Boot热部署 技术的发展总是因为人们想偷懒的心理,如果我们不想每次修改了代码,都必须重启一下服务器,并重新运行代码.那么可以配置一下热部署.有了 ...
- Spring Boot属性配置文件:application.properties 详解
学习资料 网址 官方说明文档 https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-pro ...
- 一:Spring Boot 的配置文件 application.properties
Spring Boot 的配置文件 application.properties 1.位置问题 2.普通的属性注入 3.类型安全的属性注入 1.位置问题 当我们创建一个 Spring Boot 工程时 ...
- Spring Boot 核心配置文件 bootstrap & application
Spring Boot 核心配置文件 bootstrap & application 1.SpringBoot bootstrap配置文件不生效问题 2.bootstrap/ applicat ...
- 精进 Spring Boot 03:Spring Boot 的配置文件和配置管理,以及用三种方式读取配置文件
精进 Spring Boot 03:Spring Boot 的配置文件和配置管理,以及用三种方式读取配置文件 内容简介:本文介绍 Spring Boot 的配置文件和配置管理,以及介绍了三种读取配置文 ...
- spring boot全局配置文件优先级
前两篇介绍的application配置文件,即为spring boot全局配置文件.那么spring boot加载配置文件的时候,怎么确定加载哪个目录下哪个文件呢? spring boot默认的配置文 ...
随机推荐
- Borrowers UVA - 230
I mean your borrowers of books - those mutilators of collections, spoilers of the symmetry of shel ...
- Message Decoding UVA - 213
Some message encoding schemes require that an encoded message be sent in two parts. The fifirst par ...
- 一次ssh不能登陆问题
看提示应该是进程数满了 ps -eLf | wc -l 查看当前进程数 [root@qc-app-16-63 containers]# ps -eLf | wc -l2625 查看允许最大进程数 s ...
- Selenium3自动化测试【14】元素定位之ID
元素定位 Selenium需要告知其如何去定位元素,来模拟用户动作.例如要操作Bing搜索页. 首先要找到搜索框与搜索按钮: 通过键盘输入检索的关键字: 用鼠标单击搜索按钮: 提交搜索请求. Sele ...
- Sublime Text 3 Build 3176 License
先在hosts文件里加入两行: 127.0.0.1 www.sublimetext.com 127.0.0.1 license.sublimehq.com 目的是防止Sublime Text更新和检测 ...
- hdu4515 小模拟
题意: 给你当期日期,问前D天和后D天的年月日. 思路: 直接模拟就行了水题,对了别忘了题目2013,3,5要输出这样的2013/03/05. #include<stdio ...
- Python中的时间日期模块(time、datetime)
目录 Datetime 获取当前时间 获取当前日期 获取当前时间的tuple元组 格式化日期和时间 时间移动 获取两个时间的时间差 时间格式转换 Time 获取距元年(1970.1.1)的秒数 当时时 ...
- 基于 RTF specification v1.7 的 RTF 文件解析及 OLE 对象提取(使用 Python 开发)
0x01 Office RTF 文件介绍 RTF 文件也称富文本格式(Rich Text Format, 一般简称为 RTF),意为多文本格式是由微软公司开发的跨平台文档格式.大多数的文字处理软件都能 ...
- nodejs-函数&路由
函数------------------------------------------------------------ 基本函数 function say(word) { console.log ...
- 【Git】2. Git常用命令详解、版本切换原理
一.新增文件 1.设置用户签名 签名的作用就是为了区分不同的人,方便查看版本的时候知道操作的人是谁.首次安装好git之后必须设置一下签名,否则无法提交代码. 另外,这里设置的签名跟你登录到远程仓的账号 ...