Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datasource could

在springboot开发时,创建项目运行发现报错:

Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
2023-07-18T21:21:20.914+08:00 ERROR 21528 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

Reason: Failed to determine a suitable driver class


Action:

Consider the following:
	If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
	If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).


Process finished with exit code 1

显示未配置数据源

解决办法:

添加相关数据库依赖:

implementation 'org.postgresql:postgresql:42.6.0'(我这里使用的是gradle,如使用maven搜索maven数据库依赖即可)

在application.yml文件中配置数据源即可(此为postgresSQL数据源配置,如使用mysql则搜索sql项目的application.yml配置即可)

server:
  port: 8080
spring:
  datasource:
    driver-class-name: org.postgresql.Driver
    url: jdbc:postgresql://localhost/public
    username: postgres
    password: root

mybatis:
  mapper-locations: classpath:mapper/*.xml
  configuration:
    map-underscore-to-camel-case: true
    pagehelper:
      helperDialect: PostgreSQL
      reasonable:
        true
      supportMethodsArguments:
        true
      params: count=countSql

  spring:
thymeleaf:
  prefix: classpath:/templates/
  suffix: .html
  cache: true
  mode: HTML5
  servlet:
    content-type: text/html
  encoding: utf-8

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值