我一直在尝试将h2 DB与spring引导应用程序集成,在尝试从h2-控制台连接时,我得到了以下错误
Database "mem:testdb" not found, either pre-create it or allow remote database creation (not recommended in secure environments) [90149-200] 90149/90149 (Help)
org.h2.jdbc.JdbcSQLNonTransientConnectionException: Database "mem:testdb" not found, either pre-create it or allow remote database creation (not recommended in secure environments) [90149-200]
我尝试将以下属性添加到application.properties文件中:
spring.h2.console.enabled=true
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.username=sa
spring.datasource.password=
spring.datasource.driverClassName=org.h2.Driver
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.hibernate.ddl-auto=create
它似乎仍然不起作用。
这就是我的build.gradle文件的样子
plugins {
id 'org.springframework.boot' version '2.6.3'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
group = 'com'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.data:spring-data-jpa'
runtimeOnly 'com.h2database:h2'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
tasks.named('test') {
useJUnitPlatform()
}
发布于 2022-02-11 21:55:38
如果您替换了行,它将按预期工作。
implementation 'org.springframework.data:spring-data-jpa'
使用
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
在build.gradle
中,如果您确保登录掩码中的字段JDBC具有jdbc:h2:mem:testdb
值。
如果使用Spring并添加
如果希望向最初使用Spring创建的项目添加依赖项,通常最好返回到https://start.spring.io/,添加所有依赖项,点击探索按钮,并将生成的build.gradle
复制并粘贴到现有项目中。
https://stackoverflow.com/questions/70907962
复制相似问题