本质上,是Spring的注解读取。java
@Configuration @ComponentScan(basePackages ="com.yang") @PropertySource(value= {"classpath:db.properties"},ignoreResourceNotFound=true) public class SpringConfig { @Value("${url}") private String jdbcUrl; @Value("${driver}") private String jdbcDriverClassName; @Value("${username}") private String jdbcUsername; @Bean(destroyMethod = "close") public DataSource dataSource() { BoneCPDataSource boneCPDataSource = new BoneCPDataSource(); // 数据库驱动 boneCPDataSource.setDriverClass(jdbcDriverClassName); // 相应驱动的jdbcUrl boneCPDataSource.setJdbcUrl(jdbcUrl); // 数据库的用户名 boneCPDataSource.setUsername(jdbcUsername); // 数据库的密码 boneCPDataSource.setPassword(jdbcUsername); // 检查数据库链接池中空闲链接的间隔时间,单位是分,默认值:240,若是要取消则设置为0 boneCPDataSource.setIdleConnectionTestPeriodInMinutes(60); // 链接池中未使用的连接最大存活时间,单位是分,默认值:60,若是要永远存活设置为0 boneCPDataSource.setIdleMaxAgeInMinutes(30); // 每一个分区最大的链接数 boneCPDataSource.setMaxConnectionsPerPartition(100); // 每一个分区最小的链接数 boneCPDataSource.setMinConnectionsPerPartition(5); return boneCPDataSource; } }