zoukankan      html  css  js  c++  java
  • spring PropertySource properties 文件配置

    • bean定义引入配置文件

    PropertySource注解不支持YAML files.所以只能使用properties文件

    @Configuration
    @PropertySource(value = {"classpath:permission/resource-type.properties"})
    @ConfigurationProperties("permission")
    @Data
    public class DataPermissionType {
        private String model;
        private List<Param> param;
        private Param tenant;
        private Map<String,String> map;
        private int num;
    
        @Data
        public static class Param {
            private String name;
            private List<String> value;
    
            public Param() {
            }
    
            public Param(String name, List<String> value) {
                this.name = name;
                this.value = value;
            }
        }
    }
    
    • 配置文件配置
    permission.param[0].name=TENANT
    permission.param[0].value[0]=tenant
    permission.param[1].name=MODULE
    permission.param[1].value[0]=oneservice
    permission.tenant.name=TENANT
    permission.tenant.value[0]=tenant
    permission.map.key1=value1
    permission.map.key2=value2
    permission.num=1
    permission.model=TENANT/MODULE/PROJECT/DATA
    
    • 输出结果
      DataPermissionType(model=TENANT/MODULE/PROJECT/DATA, param=[DataPermissionType.Param(name=TENANT, value=[tenant]), DataPermissionType.Param(name=MODULE, value=[oneservice])], tenant=DataPermissionType.Param(name=TENANT, value=[tenant]), map={key2=value2, key1=value1}, num=1)
    
    
    • @PropertySource支持yaml格式文件
    public class YamlPropertySourceFactory implements PropertySourceFactory {
    
        @Override
        public PropertySource<?> createPropertySource(String name, EncodedResource encodedResource) 
          throws IOException {
            YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
            factory.setResources(encodedResource.getResource());
    
            Properties properties = factory.getObject();
    
            return new PropertiesPropertySource(encodedResource.getResource().getFilename(), properties);
        }
    }
    

    参考资料

    喜欢关注一下,不喜欢点评一下
  • 相关阅读:
    window XP下 php5.5+mysql+apache2+phpmyadmin安装
    poj2478Farey Sequence
    poj2723Get Luffy Out
    niop2015day2
    P2473 [SCOI2008]奖励关
    P4284 [SHOI2014]概率充电器
    P2486 [SDOI2011]染色
    noip2015day1
    hdu 2795 Billboard
    exgcd
  • 原文地址:https://www.cnblogs.com/chengmuyu/p/15562320.html
Copyright © 2011-2022 走看看