SpringBoot启动报错“Failed to configure a DataSource: ‘url‘ attribute is not specified”
启动Spring服务报错“Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could not found”。检查application.yml文件,确认已配置spring.datasource。spring:application:name: ignite-s
·
启动Spring服务报错“Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could not found
”。
检查application.yml
文件,确认已配置spring.datasource
。
spring:
application:
name: ignite-server-7001
#数据源的配置
datasource:
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/ignite?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
password: 123456
username: root
#mybatis的配置
mybatis:
type-aliases-package: ignite.server
mapper-locations: classpath:mapper/*.xml
configuration:
map-underscore-to-camel-case: on
发现问题没?这里考验大家对yaml文件配置格式的理解程度了。
上面datasource
配置缩进不对,yaml对配置的缩进非常敏感,datasouce
多缩进,导致springboot无法正确识别datasource
的配置项。
正确的配置缩进如下:
datasource和application 、mybatis是对齐的,同一配置级别的。
spring:
application:
name: ignite-server-7001
#数据源的配置
datasource:
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/ignite?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
password: 123456
username: root
#mybatis的配置
mybatis:
type-aliases-package: ignite.server
mapper-locations: classpath:mapper/*.xml
configuration:
map-underscore-to-camel-case: on
今日踩坑,mark一下,也供参考~
更多推荐
已为社区贡献2条内容
所有评论(0)