首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >H2和h2数据库-无法连接到Spring数据库

H2和h2数据库-无法连接到Spring数据库
EN

Stack Overflow用户
提问于 2020-04-29 05:15:56
回答 2查看 1.6K关注 0票数 1

我尝试连接到我的h2数据库。我的application.properties是空的。当我尝试连接时,我得到以下错误消息:

代码语言:javascript
运行
复制
Database "mem:/~/test" not found, either pre-create it or allow remote database creation (not recommended in secure environments) [90149-200] 90149/90149

现在我将这一行添加到我的application.properties中:

代码语言:javascript
运行
复制
spring.jpa.hibernate.ddl-auto=create

现在,当我尝试重新运行Spring应用程序时,收到以下错误消息:

代码语言:javascript
运行
复制
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-04-28 23:08:20.102 ERROR 15728 --- [  restartedMain] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

An attempt was made to call a method that does not exist. The attempt was made from the following location:

    org.hibernate.jpa.boot.internal.PersistenceUnitInfoDescriptor.getValidationMode(PersistenceUnitInfoDescriptor.java:88)

The following method did not exist:

    javax.persistence.spi.PersistenceUnitInfo.getValidationMode()Ljavax/persistence/ValidationMode;

The method's class, javax.persistence.spi.PersistenceUnitInfo, is available from the following locations:

    jar:file:/C:/Users/x/.gradle/caches/modules-2/files-2.1/javax.persistence/persistence-api/1.0/5725f57873e05e068803e2bf9d5a8ea3740ffec5/persistence-api-1.0.jar!/javax/persistence/spi/PersistenceUnitInfo.class
    jar:file:/C:/Users/x/.gradle/caches/modules-2/files-2.1/jakarta.persistence/jakarta.persistence-api/2.2.3/8f6ea5daedc614f07a3654a455660145286f024e/jakarta.persistence-api-2.2.3.jar!/javax/persistence/spi/PersistenceUnitInfo.class

It was loaded from the following location:

    file:/C:/Users/x/.gradle/caches/modules-2/files-2.1/javax.persistence/persistence-api/1.0/5725f57873e05e068803e2bf9d5a8ea3740ffec5/persistence-api-1.0.jar


Action:

Correct the classpath of your application so that it contains a single, compatible version of javax.persistence.spi.PersistenceUnitInfo

我的build.gradle (依赖项)如下所示:

代码语言:javascript
运行
复制
dependencies {
    compile(group: 'javax.persistence', name: 'persistence-api', version: '1.0')
    compile(group: 'org.apache.directory.api', name: 'api-all', version: '2.0.1')
    compile 'com.h2database:h2'
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-data-rest'
    implementation 'org.springframework.boot:spring-boot-starter-mail'
    implementation 'org.springframework.boot:spring-boot-starter-security'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    compileOnly 'org.projectlombok:lombok'
    developmentOnly 'org.springframework.boot:spring-boot-devtools'
    annotationProcessor 'org.projectlombok:lombok'
    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }
    testImplementation 'org.springframework.security:spring-security-test'
}

怎么啦?

谢谢

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-04-29 05:24:05

向您的application.properties添加h2配置

代码语言:javascript
运行
复制
spring.datasource.url=jdbc:h2:mem:DBNAME
spring.datasource.username=root
spring.datasource.password=SA
spring.datasource.driverClassName=org.h2.Driver
spring.h2.console.enabled=true
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.datasource.initialize=true
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
票数 2
EN

Stack Overflow用户

发布于 2020-04-29 05:27:31

我猜想,通过向build.gradle中的compile(group: 'javax.persistence', name: 'persistence-api', version: '1.0')添加显式依赖项,您可以覆盖传递依赖项的版本,从而使api和实现不同步。尝试删除此依赖项。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61490113

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档