1.引入maven依赖
<!-- https://mvnrepository.com/artifact/com.alibaba/druid --> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>1.1.10</version> </dependency>
2.在application.yml写入配置信息
spring: datasource: type: com.alibaba.druid.pool.DruidDataSource url: jdbc:mysql://127.0.0.1:3306/seckill?serverTimezone=UTC username: root password: root driver-class-name: com.mysql.cj.jdbc.Driver # 下面为连接池设置,应用到上面的数据源中(一些最基本的设置) #初始大小 initialSize: 5 #最小 minIdle: 5 #最大 maxActive: 20 #获取连接等待超时时间 maxWait: 60000
3.编写配置类
//这样可以保证最基本的跑起来
@Configuration public class DruidConfig { @Bean @ConfigurationProperties(prefix = "spring.datasource") public DataSource druid() { return new DruidDataSource(); } }