我用spring-data-jpa dependency写了一个简单的spring项目,它用application.properties运行得很好,内容如下:
spring.application.name=customer-service
spring.datasource.url=jdbc:mysql://localhost:3306/hat
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.username=root
spring.datasource.password=
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=false但是在我把它重写成yaml文件application.yaml之后
spring:
datasource:
url: jdbc:mysql://localhost:3306/hat
driver-class-name: com.mysql.cj.jdbc.Driver
data-username: root
data-password:
jpa:
hibernate:
ddl-auto: update
show-sql: false我的项目抛出错误
Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set 我确信我把这些文件放在了正确的位置,一次只用了一个。
这两个文件不应该有相同的内容吗?我很困惑..。
发布于 2021-06-12 21:34:00
您的YAML中有几个拼写错误,因此这些文件并不相等。属性文件中有username和password,但YAML中有data-username和data-password。
这种错误的配置意味着Hibernate无法连接到数据库来检测它应该使用的方言。因此,它需要配置方言。
我相信你可以通过修正YAML来解决这个问题:
spring:
datasource:
url: jdbc:mysql://localhost:3306/hat
driver-class-name: com.mysql.cj.jdbc.Driver
username: root
password:
jpa:
hibernate:
ddl-auto: update
show-sql: falsehttps://stackoverflow.com/questions/67949198
复制相似问题