Springboot @Value读取map或list的properties配置

一、properties文件内容

config-prod.properties属性配置文件:

yjs.client.functional.filter=A,B,C,D
yjs.client.functional.map={key:"value"}

二、属性文件加载配置

PropertyProductConfig配置文件加载类

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;

/**
 * Email: love1208tt@foxmail.com
 * Copyright (c)  2019. missbe
 * @author lyg   19-7-10 下午7:48
 *
 *
 **/
@Profile({"prod","test"})
@Configuration
@PropertySource(value = "classpath:conf/config-prod.properties",ignoreResourceNotFound = true,encoding = "UTF-8")
public class PropertyProductConfig {
    @Bean
    public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer(){
        return new PropertySourcesPlaceholderConfigurer();
    }
}

三、属性对应实体类

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@SuppressWarnings("all")
public class ContainerProperties {
    private static final Logger LOGGER = LoggerFactory.getLogger(ContainerProperties.class);
    @Value(value = "#{'${yjs.client.functional.filter}'.split(',')}")
    private List<String> FUNCTION_FILTER;

    @Value("#{${yjs.client.functional.map}}")
    private Map<String, String> maps;

    public List<String> getFUNCTION_FILTER() {
        return FUNCTION_FILTER;
     }

     public void setFUNCTION_FILTER(List<String> FUNCTION_FILTER) {
        this.FUNCTION_FILTER = FUNCTION_FILTER;
     }

    public Map<String, String> getMaps() {
        return maps;
    }

    public void setMaps(Map<String, String> maps) {
        this.maps = maps;
    }
}
欢迎关注南阁公众号

南阁子也

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值