druid-spring-boot-starter:数据库连接池,集成到springboot
<dependency> <groupId>com.alibaba</groupId> <artifactId>druid-spring-boot-starter</artifactId> <version>1.1.10</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>com.oracle</groupId> <artifactId>ojdbc6</artifactId> <version>11.2.0.3</version> </dependency>
1.如上pom.xml插入配置
2.在application.properties里配置,也可以在application.yml里配置,只不过写法不一样,但也差不多
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.druid.driver-class-name=oracle.jdbc.driver.OracleDriver
#spring.datasource.druid.url=jdbc:oracle:thin:@localhost:1521:orcl
spring.datasource.druid.url=jdbc:oracle:thin:@192.168.1.11:1521:orcl
spring.datasource.druid.username=platform
spring.datasource.druid.password=platform
spring.datasource.druid.initial-size=5
spring.datasource.druid.minIdle=5
spring.datasource.druid.maxActive=20
spring.datasource.druid.maxWait=60000
spring.datasource.druid.timeBetweenEvictionRunsMillis=60000
spring.datasource.druid.minEvictableIdleTimeMillis=300000
spring.datasource.druid.validationQuery=SELECT 1 FROM DUAL
spring.datasource.druid.testWhileIdle=true
spring.datasource.druid.testOnBorrow=false
spring.datasource.druid.testOnReturn=false
spring.datasource.druid.poolPreparedStatements=true
spring.datasource.druid.maxPoolPreparedStatementPerConnectionSize=20
spring.datasource.druid.filters=stat,wall
spring.datasource.druid.connectionProperties=druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
3.开始还不了解这些属性的意思后来去挨个查了下,下面是网上资料
上面都是些常用的属性。
总结:
Druid是Java语言中最好的数据库连接池。Druid能够提供强大的监控和扩展功能。DruidDataSource支持的数据库:
理论上说,支持所有有jdbc驱动的数据库。最近发现Druid在springboot框架下有更加好用的Druid Spring Boot Starter,可以省去原本写Druid的一些配置文件或者@Configuration来配置,直接将配置写在application.yml或者application.properties里,看起来更简单一些。