【发布时间】:2021-03-11 20:15:51
【问题描述】:
我是 Spring Boot 新手,正在学习有关 udemy 开发项目的初学者课程。
下面是我的 application.properties 文件 -
application.properties
#logging
logging.level.com.vega.springit=DEBUG
info.application.name=Springit
info.application.description=Reddit clone using spring boot 2
info.application.version=0.0.1
management.endpoints.web.exposure.include=*
management.endpoint.health.show-details=always
#h2
spring.h2.console.enabled=true
#datasource (default to testdb)
spring.datasource.name=springit
h2-console 上的默认数据库仍然是 testdb
这就是我在控制台上看到的 -
2020-11-29 01:19:29.315 INFO 28396 --- [ restartedMain] o.s.b.a.h2.H2ConsoleAutoConfiguration : H2 console available at '/h2-console'. Database available at 'jdbc:h2:mem:358023a0-911e-4064-b2ec-e7046556c517'
我的问题是 -
-
为什么 h2-console 不显示 app.properties 文件中设置的数据库名称?
-
为什么控制台说数据库在 'jdbc:hs:mem:xxx' 可用?
-
当我尝试连接到 testdb 或 springit(在文件中设置)时,我收到以下错误 -
找不到数据库“C:/Users/zankh/test”,要么预先创建它,要么允许远程创建数据库(不推荐在安全环境中使用)[90149-200] 90149/90149(帮助)
也试过了,连接到'jdbc:h2:mem:springit',但仍然得到同样的错误。 我可以连接到“jdbc:hs:mem:xxx”,但这不是课程中讲师的工作方式。我在这里做错了什么?
TIA
【问题讨论】:
-
1.因为它对您配置的数据源一无所知(它对弹簧一无所知)。 2.因为那是正在启动的,3.那个db不存在所以为什么要连接。存在的数据库打印在控制台上。如果它适用于讲师,您没有遵循他的指示(即不同的 Spring Boot 版本、其他依赖项等)。
标签: spring spring-boot spring-mvc spring-data-jpa h2