gpt4 book ai didi

java - spring boot h2 无法创建数据库并登录 h2-console

转载 作者:行者123 更新时间:2023-12-02 09:32:52 26 4
gpt4 key购买 nike

我正在使用 spring boot 和 maven 来构建我的用户在线商店。我想访问我的 h2-console 数据库 onlineshop,但我无法登录,所有内容均保留为默认值。此外,数据库onlineshop也未创建。由于我使用嵌入式 tomcat,Spring Boot 不会抛出任何错误。预先感谢您的帮助。

这是我的依赖项

<!-- https://mvnrepository.com/artifact/com.h2database/h2 -->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.199</version>
<scope>runtime</scope>

应用程序属性

spring.h2.console.enabled=true
spring.datasource.platform=h2
spring.datasource.url=jdbc:h2:mem:onlineshop

错误

enter image description here

最佳答案

application.properties中设置以下属性

spring.h2.console.enabled=true
spring.datasource.url=jdbc:h2:mem:onlineshop;IFEXISTS=FALSE;DB_CLOSE_DELAY=-1
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.h2.console.path=/h2-console

IFEXISTS

By default, when an application calls DriverManager.getConnection(url, ...) with embedded URL and the database specified in the URL does not yet exist, a new (empty) database is created. In some situations, it is better to restrict creating new databases, and only allow to open existing databases. To do this, add ;IFEXISTS=TRUE to the database URL. In this case, if the database does not already exist, an exception is thrown when trying to connect

关于java - spring boot h2 无法创建数据库并登录 h2-console,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57808646/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com