import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;@Component
@ConfigurationProperties(prefix="person")
public class Person {private String name;private int age;private String uuid;private Dog dog;// standard getters and setterspublic static class Dog {private String name;private String breed;// standard getters and setters}
}
Properties 配置
person.name=John Doe
person.age=35
person.uuid=${random.uuid}
person.dog.name=Rex
person.dog.breed=Labrador
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;@Component
public class Person {@Value("${person.name}")private String name;@Value("${person.age}")private int age;@Value("${person.uuid}")private String uuid;// 内部类和其他配置略
}