@ConfigurationProperties(prefix = "app.datasource") @Component public class DataSourceConfig {
private String url;
private String username;
private int maxPoolSize;
// 标准的getter和setter方法
}

@ConfigurationProperties(prefix = "app.mail") @Component public class MailConfig {
private Server server;
private Template template;
// 静态内部类定义复杂对象
public static class Server {
private String host;
private int port;
private String username;
private String password;
// getters and setters
}
public static class Template {
private String welcomeSubject;
private String resetPasswordBody;
private boolean htmlEnabled;
// getters and setters
}
// getters and setters
}

spring: profiles:
active: dev # 默认开发环境
app: name: "Java优学网" version: "1.0.0"

@Configuration @ConditionalOnProperty(name = "app.feature.cache.enabled", havingValue = "true") public class CacheConfig {
@Bean
public CacheManager cacheManager() {
return new RedisCacheManager();
}
}
app: database-config:
connection-timeout: 5000
spring: datasource:
hikari:
maximum-pool-size: 20
minimum-idle: 5
connection-timeout: 30000
idle-timeout: 600000
max-lifetime: 1800000
connection-test-query: SELECT 1
Java优学网SpringBoot自动配置讲解:告别配置烦恼,轻松掌握自动化开发技巧
Java优学网SpringBoot整合MySQL教程:快速上手数据库开发,告别繁琐配置
Java优学网SpringBoot Starters教程:告别繁琐配置,轻松搭建企业级应用
Java优学网增强for循环教程:轻松掌握高效遍历技巧,告别繁琐代码
Java优学网SpringBoot配置绑定解析:轻松掌握配置注入技巧,告别配置错误烦恼
Java优学网Spring注解短文:轻松掌握Spring核心注解,告别繁琐配置,高效开发Java应用