属性文件格式一:对象形式
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;