赞
踩
有的是这样配置的
spring:
datasource:
druid:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/ssm_db?serverTimezone=UTC
username: root
password: 123456
这个配置文件看起来基本上是正确的,但需要注意以下几点:
spring.datasource.druid.driver-class-name:
因为你正在使用 Druid 数据源,所以应该将驱动类设置为 Druid 的驱动类,即 com.alibaba.druid.pool.DruidDataSource,而不是 com.mysql.cj.jdbc.Driver。Druid 数据源会使用自己实现的驱动。
spring.datasource.druid.url:
这里的 URL 配置基本上是正确的,指向了你的 MySQL 数据库。确保数据库名称正确,并根据需要设置其他连接参数,如字符编码、时区等。
spring.datasource.druid.username 和 spring.datasource.druid.password:
这里的用户名和密码是连接到你的 MySQL 数据库所需的凭据。请确保用户名和密码是正确的,并且具有适当的权限来访问数据库。
检查和调整配置后,你的数据源配置段应该如下所示:
spring:
datasource:
druid:
driver-class-name: com.alibaba.druid.pool.DruidDataSource
url: jdbc:mysql://localhost:3306/ssm_db?serverTimezone=UTC
username: root
password: 123456
这样配置后,你就可以在 Spring Boot 中使用 Druid 数据源来连接和操作 MySQL 数据库了。记得在项目的依赖中添加 druid 和 MySQL 驱动的相关依赖。
这样配置也可以
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/ssm_db?useSSL=false&characterEncoding=utf8
username: root
password: 123456
type: com.alibaba.druid.pool.DruidDataSource
再展示一个druid配置样例
spring: datasource: url: jdbc:mysql://localhost:3306/db_name?useSSL=false&characterEncoding=utf8 username: your_username password: your_password driver-class-name: com.mysql.jdbc.Driver type: com.alibaba.druid.pool.DruidDataSource jpa: hibernate: ddl-auto: update show-sql: true servlet: multipart: max-file-size: 10MB max-request-size: 10MB # Druid 配置 # 更多配置选项请参考 Druid 官方文档 druid: initial-size: 5 min-idle: 5 max-active: 20 test-on-borrow: true validation-query: SELECT 1 # 下面的配置示例为防火墙限制,可以根据实际情况调整 filter: stat: enabled: true exclusions: "*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*" web: enabled: true url-pattern: /druid/* username: admin password: admin logging: level: root: info org.springframework: info com.example: debug``
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。