springboot整合druid数据库连接池

2018-01-08 13:36:15来源:oschina作者:xiaomin0322人点击

分享

1.添加starter依赖。druid,数据库驱动,配置依赖 com.alibaba druid-sprin...


1.添加starter依赖。druid,数据库驱动,配置依赖




com.alibaba
druid-spring-boot-starter
1.1.5



org.springframework.boot
spring-boot-configuration-processor
true



com.oracle
ojdbc6
11.1.0.6

2. 在application.properties添加配置项


#--------------------druid--------------------------------
#JDBC
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
spring.datasource.druid.url=jdbc:oracle:thin:@ip:port:orcl
spring.datasource.druid.username=******
spring.datasource.druid.password=******
spring.datasource.druid.initial-size=10
spring.datasource.druid.min-idle=5
spring.datasource.druid.max-active=50
spring.datasource.druid.max-wait=60000
spring.datasource.druid.time-between-eviction-runs-millis=60000
spring.datasource.druid.min-evictable-idle-time-millis=300000
spring.datasource.druid.validation-query=SELECT1FROMDUAL
spring.datasource.druid.test-while-idle=false
spring.datasource.druid.test-on-return=false
spring.datasource.druid.test-on-borrow=false
spring.datasource.druid.filters=stat,wall,log4j,config
spring.datasource.druid.connection-properties=druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
#webstat
spring.datasource.druid.web-stat-filter.enabled=true
spring.datasource.druid.web-stat-filter.exclusions=*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*
#statview
spring.datasource.druid.stat-view-servlet.enabled=true
spring.datasource.druid.stat-view-servlet.allow=127.0.0.1
spring.datasource.druid.stat-view-servlet.deny:192.168.0.10
spring.datasource.druid.stat-view-servlet.login-username=root
spring.datasource.druid.stat-view-servlet.login-password=java
spring.datasource.druid.stat-view-servlet.reset-enable=false

3.添加数据库连接池的bean


packagecom.caiwufei.springboot;
importjavax.sql.DataSource;
importorg.mybatis.spring.annotation.MapperScan;
importorg.springframework.boot.SpringBootConfiguration;
importorg.springframework.boot.context.properties.ConfigurationProperties;
importorg.springframework.cache.annotation.EnableCaching;
importorg.springframework.context.annotation.Bean;
importorg.springframework.context.annotation.ComponentScan;
importcom.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder;
@SpringBootConfiguration
@ComponentScan(value="com.caiwufei")
@MapperScan(basePackages={"com.caiwufei.module.*.dao"})
@EnableCaching
publicclassAppContextConfig{
@Bean
@ConfigurationProperties("spring.datasource.druid")
publicDataSourcedataSource(){
returnDruidDataSourceBuilder.create().build();
}

}

最新文章

123

最新摄影

闪念基因

微信扫一扫

第七城市微信公众平台