-1.加入druid的依赖:
<!--druid依赖-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.4</version>
</dependency>
-2 加入连接池配置:
#jdbc配置
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/resturant?useUnicode=true&characterEncoding=UTF-8
spring.datasource.username=root
#生成的加密后的密码
spring.datasource.password=BQjdji7y9nUZqkoOhdWxdLlDldS3/y4w5BNlmtejHp/O+rZAmkmM9MYvUrWSyAhZf9EEPj2KIdKi8u4oqdXspg==
#生成的公钥
public-key=MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAJyvDBtFS2Wok00mhzyVhRP/14lveckDTR6XhQoCxmVPicf7Ca4BeGri+PAenawVQkuKTcRZ0QVrFv7B25VMUKUCAwEAAQ==
#配置connection-properties,启用加密,配置公钥。
spring.datasource.druid.connection-properties=config.decrypt=true;config.decrypt.key=${public-key}
#启用ConfigFilter
spring.datasource.druid.filter.config.enabled=true
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
#连接池配置
spring.datasource.druid.initial-size=2
spring.datasource.druid.max-active=20
spring.datasource.druid.min-idle=1
spring.datasource.druid.max-wait=60000
spring.datasource.druid.pool-prepared-statements=true
spring.datasource.druid.validation-query=SELECT 1
spring.datasource.druid.test-on-borrow=false
spring.datasource.druid.test-on-return=false
spring.datasource.druid.test-while-idle=true
spring.datasource.druid.time-between-eviction-runs-millis=60000
spring.datasource.druid.min-evictable-idle-time-millis=30000
spring.datasource.druid.filters=mergeStat
我这里还对数据库密码进行了加密,如何对数据库密码进行加密可以参考:http://blog.csdn.net/Hzt_fighting_up/article/details/78167129
更多对druid的配置可以参考:
https://github.com/alibaba/druid/tree/master/druid-spring-boot-starter