在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