1.首先引入相关依赖
com.alibaba
druid-spring-boot-starter
1.1.10
org.postgresql
postgresql
runtime
org.springframework.boot
spring-boot-starter-jdbc
2.配置yml
spring:
datasource:
druid:
driver-class-name: org.postgresql.Driver
url: jdbc:postgresql://ip:port/**?&ssl=false
username: postgres
password: 123456
initial-size: 1
max-active: 128
min-idle: 96
filter:
stat:
log-slow-sql: true
db-type: postgresql
enabled: true
3.配置类
@Slf4j
@Configuration
public class DruidConfig {
@ConfigurationProperties(prefix = "spring.datasource.druid")
@Bean(destroyMethod = "close", initMethod = "init") //第一次使用,页面会出现(*) property for user to setup