springboot属性统一配置,分层级

app.user.name=John Doe
app.user.age=30
app.user.address.city=New York
app.user.address.country=USA
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
 
@Configuration
@ConfigurationProperties(prefix = "app")
public class AppConfig {
 
    private User user;
 
    public User getUser() {
        return user;
    }
 
    public void setUser(User user) {
        this.user = user;
    }
 
    public static class User {
        private String name;
        private int age;
        private Address address;
 
        // getters and setters
 
        public static class Address {
            private String city;
            private String country;
 
            // getters and setters
        }
    }
}

 

posted on 2024-07-24 08:31  五官一体即忢  阅读(4)  评论(0编辑  收藏  举报

导航