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 } } }
吾乃代码搬运工,侵联删