提取属性文件或yml文件

属性文件格式一:对象形式

1、application.yml

thread:
 corePoolSize: 30
 maxPoolSize: 50
 queueCapacity: 1000
 keepAliveSeconds: 300

2、配置类

@Data
@NoArgsConstructor
@AllArgsConstructor
@Configuration
@ConfigurationProperties(prefix = "thread")//前缀
//如果文件名为application.yml,且在resource一级目录中,则可忽略
@PropertySource(value = "classpath:config/application.yml",ignoreResourceNotFound = true)
public class ThreadPoolSettings {
    // 核心线程数
    private Integer corePoolSize;

    // 最大线程数
    private Integer maxPoolSize;

    // 队列最大长度
    private Integer queueCapacity;

    // 线程池维护线程所允许的空闲时间
    private Integer keepAliveSeconds;
}

3、应用形式

@Autowired
private ThreadPoolSettings threadPoolSettings;

 

属性文件格式二:Map形式

1、application.yml

customer:
  discount :
    1 : com.huace.thread.com.huace.pattern.strategy.OrgnicCustomer

    2 : com.huace.thread.com.huace.pattern.strategy.VipCustomer

    3 : com.huace.thread.com.huace.pattern.strategy.SuperVipCustomer

2、配置类

@Data
@NoArgsConstructor
@AllArgsConstructor
@Configuration
@ConfigurationProperties(prefix = "customer")
@PropertySource(value = "classpath:/application.yml",ignoreResourceNotFound = true)
public class PropertiesConfig {

    public  Map<String,String> discount = new HashMap<>();
}

3、应用形式

@Autowired
private PropertiesConfig propertiesConfig;

 

属性文件格式三:集合形式

1、application.yml

customer:
  students :
   - name : chenmingjian
     age  : 25
     city : shenzhen

   - name : wangyuxuan
     age  : 26
     city : shenzhen

2、配置类

@Data
@NoArgsConstructor
@AllArgsConstructor
@Configuration
@ConfigurationProperties(prefix = "customer")
public class StudentSetting {

    private List<Student> students;
}

3、应用形式

@Autowired
private StudentSetting studentSetting;

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值