spring boot配置MySQL8.0 Druid数据源


创建spring boot项目,在pom中添加相应依赖

<!--web-->
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<!--mysql-->
<dependency>
	<groupId>mysql</groupId>
	<artifactId>mysql-connector-java</artifactId>
	<scope>runtime</scope>
</dependency>

<!--druid-->
<dependency>
	<groupId>com.alibaba</groupId>
	<artifactId>druid-spring-boot-starter</artifactId>
	<version>1.1.10</version>
</dependency>

<!--jdbc-->
<dependency>
	<groupId>org.springframework</groupId>
	<artifactId>spring-jdbc</artifactId>
</dependency>

在application.yml文件中配置数据源

spring:
  application:
    name: cloud-account
  datasource:
    type: com.alibaba.druid.pool.DruidDataSource
    url: jdbc:mysql://localhost:3306/db?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&useSSL=true
    driver-class-name: com.mysql.cj.jdbc.Driver
    username: root
    password: root
  druid:
    initial-size: 3
    min-idle: 3
    max-active: 10
    max-wait: 60000
    stat-view-servlet:
    login-username: admin
    login-password: admin
  filter:
    stat:
    log-slow-sql: true
    slow-sql-millis: 2000

启动后可以通过http:hostname:port/druid/index.html访问Druid后台监控界面。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM