经过很长一段时间,我才刚刚开始了一个新的Spring项目,我不知道到底有什么不能使一个简单的配置工作。
我从一些简单的东西开始,比如DB连接,如下所示:
spring:
datasource:
platform: postgres
host: jdbc:postgresql://localhost
port: 54322
database: 123
username: abc
password: asd我只有@SpringBootApplication注释,所以我没有手动配置任何东西。
但是,当我运行这个程序时,由于找不到足够的DB信息,它失败了。
我的db依赖项
implementation 'org.postgresql:postgresql:42.1.4'
implementation 'io.r2dbc:r2dbc-postgresql'
runtimeOnly 'org.postgresql:postgresql'知道这是为什么吗?
当我将datasource 放在spring:标记的之外时,它会工作。
发布于 2022-06-21 08:54:37
spring: datasource: platform: postgres主机: jdbc:postgresql://localhost端口: 54322数据库:123个用户名: abc密码: asd
您必须调整属性的级别。
spring:
datasource:
platform: postgres
host: jdbc:postgresql://localhost
port: 54322
database: 123
username: abc
password: asd发布于 2022-06-21 22:15:22
就像你说的,你很长时间以来一直在使用弹簧靴。
您引用的属性(.platform)用于SpringBoot1.x (例如:)。
但是最近的版本是2.x,属性略有变化。查看这里的新参考文档:https://docs.spring.io/spring-boot/docs/2.7.0/reference/html/data.html#data.sql.datasource.configuration
对于postgres url,请检查https://jdbc.postgresql.org/documentation/80/connect.html。
spring:
datasource:
# platform is auto-detected now
url: jdbc:postgresql://localhost:54332/123
username: abc
password: asd如果您将它从spring“标记”中移出,它就会工作,因为Spring随后会配置内存中的电子信息数据库。
https://stackoverflow.com/questions/72692163
复制相似问题