搜索
查看
编辑修改
首页
UNITY
NODEJS
PYTHON
AI
GIT
PHP
GO
CEF3
JAVA
HTML
CSS
搜索
花生_TL007
这个屌丝很懒,什么也没留下!
关注作者
热门标签
jquery
HTML
CSS
PHP
ASP
PYTHON
GO
AI
C
C++
C#
PHOTOSHOP
UNITY
iOS
android
vue
xml
爬虫
SEO
LINUX
WINDOWS
JAVA
MFC
CEF3
CAD
NODEJS
GIT
Pyppeteer
article
热门文章
1
面试15:59进去的,16:08就出来了,问的实在是太...
2
葡萄酒(WINE)数据集分类(PyTorch实现)_wine数据集
3
【嵌入式芯片】GPU,CPU,SOC,DSP,FPGA,ASIC,MCU,MPU,GPP,ECU等简介_嵌入式芯片分类
4
Mysql学习宝典(三) -- Mysql索引原理以及应用解析并对数据结构进行推演_数据库的索引是dbms建立
5
机器学习-10-神经网络python实现-从零开始
6
Mysql中的CASE WHEN_mysql case when
7
全面了解链上身份之Web3社交及相关项目_web3社交项目
8
.Net 6 基础_.net6
9
.NET WebApi 发布到服务器(windows)并开放端口_.net core web api 发布
10
为什么年轻人喜欢玩QQ,而年纪大的人喜欢玩微信!_年轻人(30岁以下)是否比年长的人(包括老人)更喜欢用微信与亲友联系而不是电话
当前位置:
article
> 正文
SpringBoot @ConfigurationProperties参数绑定 详解_@configproperties列表
作者:花生_TL007 | 2024-04-13 00:11:49
赞
踩
@configproperties列表
1> 引入 spring-boot-configuration-processor 库
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
2> 在 application.yml 中要获取的数据
myprops:
# 自定义的属性和值
simple-prop: simplePropValue
array-props: 1,2,3,4,5
list-prop1:
- name: abc
value: abcValue
- name: efg
value: efgValue
list-prop2:
- config2Value1
- config2Vavlue2
map-props:
key1: value1
key2: value2
注 : 1> 注意命名规则,根节点不能采用驼峰命名法,否则将会导致识别失败这是在 2.0.1.RELEASE 出现的问题,最好全部小写,剩余的其他字段可以采用驼峰命名法,可以使用 - 方式来修改
2> 注意查看日志中的提示信息
3> 使用 @ConfigurationProperties 将数据绑定到对象上有两种方式
方式1> 在方法上引入 @ConfigurationProperties 注解
public class MyProps {
private String simpleProp;
private String[] arrayProps;
/** 接收prop1里面的属性值 */
private List<Map<String, String>> listProp1 = new ArrayList<>();
/** 接收prop2里面的属性值 */
private List<String> listProp2 = new ArrayList<>();
/** 接收prop1里面的属性值 */
private Map<String, String> mapProps = new HashMap<>();
public String getSimpleProp() {
return simpleProp;
}
/**
* String类型的一定需要setter来接收属性值;maps, collections, 和 arrays 不需要
* @param simpleProp
*/
public void setSimpleProp(String simpleProp) {
this.simpleProp = simpleProp;
}
public String[] getArrayProps() {
return arrayProps;
}
public void setArrayProps(String[] arrayProps) {
this.arrayProps = arrayProps;
}
public List<Map<String, String>> getListProp1() {
return listProp1;
}
public void setListProp1(List<Map<String, String>> listProp1) {
this.listProp1 = listProp1;
}
public List<String> getListProp2() {
return listProp2;
}
public void setListProp2(List<String> listProp2) {
this.listProp2 = listProp2;
}
public Map<String, String> getMapProps() {
return mapProps;
}
public void setMapProps(Map<String, String> mapProps) {
this.mapProps = mapProps;
}
}
# 使用在方法上
@Bean
@ConfigurationProperties(prefix = "myprops")
public MyProps myProps() {
return new MyProps();
}
方式2> 在类上使用 @ConfigurationProperties 注解
@Component
@ConfigurationProperties(prefix = "myprops")
public class MyProps {
private String simpleProp;
private String[] arrayProps;
/** 接收prop1里面的属性值 */
private List<Map<String, String>> listProp1 = new ArrayList<>();
/** 接收prop2里面的属性值 */
private List<String> listProp2 = new ArrayList<>();
/** 接收prop1里面的属性值 */
private Map<String, String> mapProps = new HashMap<>();
public String getSimpleProp() {
return simpleProp;
}
/**
* String类型的一定需要setter来接收属性值;maps, collections, 和 arrays 不需要
*
* @param simpleProp
*/
public void setSimpleProp(String simpleProp) {
this.simpleProp = simpleProp;
}
public String[] getArrayProps() {
return arrayProps;
}
public void setArrayProps(String[] arrayProps) {
this.arrayProps = arrayProps;
}
public List<Map<String, String>> getListProp1() {
return listProp1;
}
public void setListProp1(List<Map<String, String>> listProp1) {
this.listProp1 = listProp1;
}
public List<String> getListProp2() {
return listProp2;
}
public void setListProp2(List<String> listProp2) {
this.listProp2 = listProp2;
}
public Map<String, String> getMapProps() {
return mapProps;
}
public void setMapProps(Map<String, String> mapProps) {
this.mapProps = mapProps;
}
}
以上两种方法,任意一种均可,之后就可以直接使用
@Autowired
private MyProps myProps;
@Test
public void propsTest() {
System.out.println("simpleProp: " + myProps.getSimpleProp());
}
声明:
本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:
https://www.wpsshop.cn/w/花生_TL007/article/detail/413345
推荐阅读
article
2分钟
Docker
部署
SprinBoot
集成 Flowable 工作流引擎_
flowable
...
文章目录一、 简介二、 docker流程引擎部署2.1. jdk安装配置2.2. 下载打包好的tar包2.3. 上传ta...
赞
踩
article
【
开源
项目】基于
SpringBoot
+
Vue
实现的
可视化
拖拽编辑的
大屏
项目_
大屏
开源
框架...
简介
大屏
设计(AJ-Report)是一个
可视化
拖拽编辑的全
开源
项目,直观,酷炫,具有科技感的图表工具。内置的基础功能包括...
赞
踩
article
可视化
大屏
设计
BI
平台【
SpringBoot
+
MyBatisPlus
】【
开源
】【分享】_
大屏
设计
器开...
AJ-Report是一个完全
开源
的
BI
平台,酷炫
大屏
展示,能随时随地掌控业务动态,让每个决策都有数据支撑。多数据源支持,...
赞
踩
article
SpringBoot
(学习笔记)_
spring
boot
2.3
...
javase:OOPMySQL:持久化html+css+js+jquery+框架:视图,框架不熟练,css不好javaw...
赞
踩
article
springboot
集成
Swagger3
(速通)_
springboot
集成
swagger3
...
一杯奶茶的时间学会使用
springboot
集成
swagger3
_
springboot
集成
swagger3
springbo...
赞
踩
article
Springboot 集成
swagger3
_
springboot
集成
swagger3
...
2.swagger 启动配置3.swagger注解1)启动类中添加 @EnableOpenApi 注解2)control...
赞
踩
article
使用
Java
+
Springboot
+Mysql开发
个性化
租房
推荐
系统 在线
房屋
租赁
推荐
系统 基于机器...
前台用户包含:注册、登录、退出登录、浏览
房屋
、搜索
房屋
、信息修改、密码修改、
房屋
评分、
房屋
收藏、
房屋
评论、用户留言、排行...
赞
踩
article
SpringBoot 整合
Netty
+
Websocket
_springboot
netty
w...
最近项目中需要用到长连接服务,特地整合
Netty
+
Websocket
。我们系统需要给用户主动推送订单消息,还有强制用户下...
赞
踩
article
SpringBoot 整合
Netty
实现
WebSocket
...
SpringBoot 整合
Netty
实现
WebSocket
SpringBoot 整合
Netty
实现 WebSo...
赞
踩
article
##
springboot
集成基于
netty
的
websocket
详解
##
_
springboot
...
1、WebSocket简介WebSocket协议是基于TCP的一种新的网络协议。它实现了浏览器与服务器全双工(full-...
赞
踩
article
Springboot
+
Netty
+
WebSocket
搭建简单的
消息
通知
_
netty
做websocke...
"
Netty
-
WebSocket
服务器。"
Netty
-
WebSocket
服务器。"您的浏览器不支持
WebSocket
协议...
赞
踩
article
SpringBoot+
WebSocket
+
Netty
实现
消息
推送_
springboot
+ nett...
Netty
实现
消息
推送_
springboot
+
netty
+
websocket
实现推送
消息
springboot
+...
赞
踩
article
【
Java
网络编程与IO流】
SpringBoot
+
WebSocket
+
Netty
实现实时的服...
SpringBoot
+
WebSocket
+
Netty
实现消息推送一、基础知识Websocket是一种在单个TCP...
赞
踩
article
SpringBoot+
Netty
+
WebSocket
实现简单的在线聊天小功能_
springboot
集...
SpringBoot+
Netty
+
WebSocket
实现简单的在线聊天小功能_
springboot
集成
netty
实现we...
赞
踩
article
SpringBoot
+Vue 整合
websocket
实现简单
聊天
窗口
_
springboot
+
vue
简...
1 输入临时名字充当账号使用2 进入
聊天
窗口
3 发送消息 (复制一个页面,输入其他名字,方便展示效果)4 其他
窗口
效果。...
赞
踩
article
基于
Java
+
SpringBoot
+
Vue
前后端分离
聊天
即时通讯系统设计与
实现
_基于
vue
和unia...
博主介绍:✌全网粉丝3W+,全栈开发工程师,从事多年软件开发,在大厂呆过。持有软件中级、六级等证书。可提供微服务项目搭建...
赞
踩
article
SpringBoot
:
Netty
-
SocketIO
+ VUE:
SocketIO
实现
前后端实时双向通...
WebSocket是HTML5新增的一种全双工通信协议,客户端和服务端基于TCP握手连接成功后,两者之间就可以建立持久性...
赞
踩
article
WebSocket
+ SpringBoot + VUE实现后
端
实时向前
端
推送消息_springbo...
一、目的众所周知,正常来说在前后
端
通信中,后
端
往往处于一个被动的状态,对前
端
的请求作出对应的响应。但有的时候我们会遇到需...
赞
踩
article
SpringBoot
+Netty+Vue+Websocket实现在线
推送
/聊天系统_
netty
+vu...
ok,那么今天的话也是带来这个非常常用的一个技术,那就是咱们完成nutty的一个应用,今天的话,我会介绍地很详细,这样的...
赞
踩
article
Springboot
+
Netty
+Vue实现
聊天
(单聊+创建群聊并
聊天
)_
springboot
+v...
Springboot
+
Netty
+Vue实现简单的单对单
聊天
后台项目结构pom文件主要在SpringBoot项目的po...
赞
踩
相关标签
docker
可视化
spring boot
开源
后端
java
idea
springboot
swagger
人工智能
深度学习
机器学习
协同过滤
Netty
Websocket
NIO
长连接
websocket