我正在学习 Spring Boot,我正在尝试创建一个非常简单的 RESTful API,它可以访问内存数据库并执行 CRUD 操作。
但是,每次我尝试在http://localhost:8080/h2-console上连接或测试连接时,我都会收到此错误:
“未找到数据库“C:/Users/XXX/test”,并且 IFEXISTS=true,因此我们无法自动创建它 [90146-199] 90146/90146”
我完全按照http://www.springboottutorial.com/spring-boot-crud-rest-service-with-jpa-hibernate的说明进行操作。我已经尝试了我可以在网上找到的所有内容:使用 jdbc:h2:mem:test 作为 JDBC URL 等,但它们都没有为我工作,我不确定我做错了什么。我没有从官方网站安装h2数据库,因为我读到它没有必要使用内存模块(我仍然不知道我是否应该安装它,因为没有提到据我检查,它是在线的)。
有什么想法吗?我是 Spring Boot 的初学者,我真的很迷茫。我只想测试 CRUD 操作,而不关心数据库的持久性。
我在下面提供了我的 application.properties。
谢谢!:)
# H2
spring.h2.console.enabled=true
spring.h2.console.path=/h2
# Datasource
spring.datasource.url=jdbc:h2:mem:test
spring.datasource.username=user
spring.datasource.password=user
spring.datasource.driver-class-name=org.h2.Driver
Run Code Online (Sandbox Code Playgroud)
确保您的网址h2-console(refer screenshot below)与您的“ spring.datasource.url=jdbc:h2:mem:test”相同。
它对我有用。
更新:其他替代解决方案是,您可以避免设置spring.datasource.url属性。Spring 会自动为你设置这个默认的 JDBC url。
happy learning.. Upvote, if it is sovled your issue.
| 归档时间: |
|
| 查看次数: |
3544 次 |
| 最近记录: |