my.properties

master.pool[0].id=poolId001
master.pool[0].endpoint=http://192.168.1.101:8080/v1
master.pool[1].id=poolId002
master.pool[1].endpoint=http://192.168.1.102:8080/v1
master.pool[2].id=poolId003
master.pool[2].endpoint=http://192.168.1.103:8080/v1

对应的Java POJO

package com.ssslinppp.model;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils; import java.util.List; @ConfigurationProperties(prefix = "master")
@PropertySource("classpath:my.properties")
@Component
public class PropertiesList {
private List<PoolConfiguration> pool; public static class PoolConfiguration { private String id; private String endpoint; public String getId() {
return id;
} public void setId(String id) {
this.id = id;
} public String getEndpoint() {
return endpoint;
} public void setEndpoint(String endpoint) {
this.endpoint = endpoint;
} @Override
public String toString() {
return "PoolConfiguration{" +
"id='" + id + '\'' +
", endpoint='" + endpoint + '\'' +
'}';
}
} public String endpoint(String poolId) {
if (CollectionUtils.isEmpty(pool))
return null; for (PoolConfiguration config : pool) {
if (config.getId().equals(poolId)) {
return config.getEndpoint();
}
}
return null;
} public List<PoolConfiguration> getPool() {
return pool;
} public void setPool(List<PoolConfiguration> pool) {
this.pool = pool;
} @Override
public String toString() {
return "PropertiesList{" +
"pool=" + pool +
'}';
}
}

测试

package com.ssslinppp.controller;

import com.ssslinppp.commons.properties.PropertiesGet;
import com.ssslinppp.model.PropertiesList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; @RestController
@RequestMapping("/prop")
public class PropController { @Autowired
private PropertiesList propertiesList; @RequestMapping("/printProps")
public String printProps(){
System.out.println(propertiesList.toString());
return propertiesList.toString();
} }

输出

PropertiesList{pool=[PoolConfiguration{id='poolId001', endpoint='http://192.168.1.101:8080/v1'}, PoolConfiguration{id='poolId002', endpoint='http://192.168.1.102:8080/v1'}, PoolConfiguration{id='poolId003', endpoint='http://192.168.1.103:8080/v1'}]}

【Properties】在Properties中配置List的更多相关文章

  1. Spring中配置和读取多个Properties文件--转

    public class PropertiesFactoryBeanextends PropertiesLoaderSupportimplements FactoryBean, Initializin ...

  2. application.properties多环境配置文件、jar包外部配置文件、配置项加密、程序中配置使用

    一.简介 spring boot项目application.properties文件存放及使用介绍 二.方法一多环境配置文件 我们一般都会有多个应用环境,开发环境.测试环境.生产环境,各个环境的配置会 ...

  3. Hibernate 中配置属性详解(hibernate.properties)

    Hibernate能在各种不同环境下工作而设计的, 因此存在着大量的配置参数.多数配置参数都 有比较直观的默认值, 并有随 Hibernate一同分发的配置样例hibernate.properties ...

  4. SpringBoot在logback.xml中读取application.properties中配置的日志路径

    1.在springboot项目中使用logback记录日志,在logback.xml中配置日志存储位置时读取application.properties中配置的路径,在 logback.xml中配置引 ...

  5. maven 打包时动态替换properties资源文件中的配置值

    pom build节点下面添加resource配置: <resources> <resource> <directory>src/main/resources/&l ...

  6. Java中如何获取spring中配置的properties文件内容

    有2种方式: 一. 1.通过spring配置properties文件 [java]  <bean id="propertyConfigurer"      class=&qu ...

  7. Spring Boot为我们准备了最佳的数据库连接池方案,只需要在属性文件(例如application.properties)中配置需要的连接池参数即可。

    Spring Boot为我们准备了最佳的数据库连接池方案,只需要在属性文件(例如application.properties)中配置需要的连接池参数即可.

  8. 使用 application.properties 中配置的属性,举例:@Value("${server.port}")

    使用 application.properties 中配置的属性:@Value 注解. @RestController public class HelloWorldController { @Val ...

  9. Java 读取application.properties配置文件中配置

    实际开发中若需要读取配置文件application.properties中的配置,代码如下.例:读取配置文件中name属性配置值: 代码如下: import org.springframework.c ...

  10. log4j.properties 详解与配置步骤(转)

    找的文章,供参考使用 转自 log4j.properties 详解与配置步骤 一.log4j.properties 的使用详解 1.输出级别的种类 ERROR.WARN.INFO.DEBUGERROR ...

随机推荐

  1. Unity 3D动态修改Shader状态,使物体透明等等

    Unity动态改Shader状态透明 本文提供全流程,中文翻译. Chinar 坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 -- 高分辨率用户请根据需求调整网页缩放比例) Chinar -- ...

  2. input标签(按钮)

    按钮: <input type="button" name="..." value="..." /> <input typ ...

  3. Gym101986: Asia Tsukuba Regional Contest(寒假自训第12场)

    A .Secret of Chocolate Poles 题意:有黑白两种木块,黑色有1,K两种长度: 白色只有1一种长度,问满足黑白黑...白黑形式,长度为L的组合种类. 思路:直接DP即可. #i ...

  4. CodeForces - 1100F:Ivan and Burgers (线性基&贪心)(离线 在线)

    题意:给定N个数,Q次询问,求区间最大异或和. 思路:一开始想的线性基+线段树.单次线性基合并的复杂度为20*20,结合线段树,复杂度为O(NlogN*20*20):显然,超时. 超时代码: #inc ...

  5. Formal Grammars of English -10 chapter(Speech and Language Processing)

    determiner  限定词 DET propernoun 专有名词 NP (or noun phrase) mass noun 不可数名词 Det Nouns 限定词名词 relative pro ...

  6. 特殊符号 sort_wc_uniq命令 tee_tr_split命令

     *     任意个 任意字符 ?    任意一个字符  #     注释字符   \     转意符   |     管道符  (之前有说过) cut  命令: cut  -d "&quo ...

  7. 2017.4.9 函数式编程FP

    函数编程(简称FP)不只代指Haskell Scala等之类的语言,还表示一种编程范式,和面向对象的编程方式一样,是编程思维,软件思考方式,也称面向函数编程. 编程的本质是组合,组合的本质是范畴Cat ...

  8. (7)MySQL的事务

    什么是事物: 作用:一个事务(transaction)中的所有操作,要么全部完成,要么全部不完成,不会结束在中间某个环节.事务在执行过程中发生错误,会被回滚(Rollback)到事务开始前的状态,就像 ...

  9. hdu6441 Find Integer (费马大定理)

    #include<bits/stdc++.h> using namespace std; int main() { int T; scanf("%d",&T); ...

  10. redis源码之压缩列表ziplist

    压缩列表ziplist1.简介连续,无序的数据结构.压缩列表是 Redis 为了节约内存而开发的, 由一系列特殊编码的连续内存块组成的顺序型(sequential)数据结构. 2.组成 属性 类型 长 ...