spring PropertySource properties 文件配置

  • bean定义引入配置文件
@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)

上一篇:2021-09-10


下一篇:spring以及spring boot参数配置