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. [LeetCode&Python] Problem 598. Range Addition II

    Given an m * n matrix M initialized with all 0's and several update operations. Operations are repre ...

  2. BZOJ4426 :最大生产率(贪心+决策单调性DP)

    题意:给出N个人,现在让你分P组,每组的工作效率是最小结束时间-最大开始时间,要求每一组的效率的正数,求最大效率和.N<1000 思路: 把包含至少一个其他的分到A组:否则到B组. A组的要么单 ...

  3. nginx安装,配置,并可以放静态文件教程

    简单介绍一下:nginx是一个高性能的HTTP和反向代理的服务器.能有处理最高5,0000的并发量,是新兴的一个代理服务器.中国大陆使用nginx网站用户有:百度.京东.新浪.网易.腾讯.淘宝等. 安 ...

  4. HDU 1159:Common Subsequence(LCS模板)

    Common Subsequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  5. javascript 日常

    $('#code').bind('keypress', function (e) { //绑定回车处理 ) { console.log($("#code")); } }); $.a ...

  6. #366 A-C

    A. Hulk 题意是给你一个n 输出一个英文字符串,找下规律就发现 当(i!=n&&i%2==1) 输出的是 I hate that (注意大写) 当(i!=n&&i ...

  7. Hadoop权威指南

    初识Hadoop Hadoop与其它系统比较 数据库的劣势:磁盘寻址性能低发展慢 数据库索引? MapReduce适合一次写入,多次读取的应用,关系型数据库适合持续更新的数据集 Hadoop在处理数据 ...

  8. mysql 开启binlog

    登录mysql之后使用下面的命令查看是否开启binlog show variables like 'log_%'; if没有开启则在mysql的配置文件中 加入以下内容 server_id=2 log ...

  9. itcast-spring-三大框架整合

    三大框架架构(整合原理) struts整合到spring   hibernate整合到spring 导包 eclipse需要导入   myeclipse不用 单独配置spring容器 单独配置stru ...

  10. java的数组和arraylist

    1.数组 1.0   一开始就错了 int a[8];   //没有像C在内存中开辟了8个区域 改: int a[] = {1,2,3} ; System.out.println(a.length); ...