SpringBoot @ConfigurationProperties使用详解

2020-02-11 12:03:23王冬梅

conversion.employee=john,2000

我们需要自己实现一个Converter接口的转换类:

@Component
@ConfigurationPropertiesBinding
public class EmployeeConverter implements Converter<String, Employee> {
 
  @Override
  public Employee convert(String from) {
    String[] data = from.split(",");
    return new Employee(data[0], Double.parseDouble(data[1]));
  }
}

本文的例子可以参看: https://github.com/ddean2009/learn-springboot2/tree/master/springboot-ConfigurationProperties

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持易采站长站。