SpringBoot之十二:SpringBoot读取配置文件
2018-04-03 08:26
671 查看
一、读取.properties文件
本质上,是Spring的注解读取。@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; } }
相关文章推荐
- springboot读取配置文件的三种方式
- SpringBoot内部配置:“application.properties配置”和”使用XML配置”,读取属性文件中的内容,日志配置,Profile配置(学习:SpringBoot实战)
- Spring boot读取配置文件总结
- Spring-boot中读取config配置文件的两种方式
- Springboot学习笔记之读取全局配置文件参数
- SpringBoot读取配置文件注入到配置类
- SpringBoot实战之2 读取配置文件
- Springboot 之 自定义配置文件及读取配置文件
- springboot如何读取配置文件(application.yml)中的属性值
- Spring-boot中读取config配置文件的两种方式
- springboot如何读取配置文件中的参数(例如:application-consts.properties) 又结合maven读取配置文件的顺序
- spring boot 读取配置文件(application.yml)中的属性值
- springboot读取配置文件
- springboot学习笔记2(拦截器,redis,授权登录,读取yml配置文件)
- Spring-boot中读取config配置文件的两种方式
- springBoot 读取不同环境的配置文件
- spring-boot读取props和yml配置文件的方法
- spring-boot读取props和yml配置文件
- Springboot 之 自定义配置文件及读取配置文件注意:配置文件中的字符串不要有下划线 .配置中 key不能带下划线,value可以(下划线的坑,坑了我两天..特此纪念)
- Springboot 之 自定义配置文件及读取配置文件