1. /**
    2. * 只有在容器中的组件,配置绑定才生效
    3. */
    4. @Component
    5. @ConfigurationProperties(prefix = "mycar")
    6. public class Car {
    7. private String brand;
    8. private Integer price;
    9. }

    绑定配置文件中以 mycar 开头的配置
    application.properties

    1. mycar.brand=小米
    2. mycar.price=100