使用Spring Boot(Java 10)设置Hibernate + JPA

时间:2018-09-30 13:12:02

标签: java hibernate spring-boot spring-data-jpa java-10

我试图基于此example使用Hibernate + JPA设置一个示例Spring Boot项目。当我尝试使用定义的简单entity类运行应用程序时,出现以下错误:

  

java.lang.NoClassDefFoundError: javax/transaction/SystemException

这个问题已经在SO中提出。给出的答案是添加缺少的jta.jar。但是此解决方案不起作用,因为该项目无法使用上述依赖项进行编译,因为Gradle抱怨无法解决/找到该依赖项。

以下是我的gradle文件。

buildscript {
    ext {
        springBootVersion = '2.0.4.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        classpath "io.spring.gradle:dependency-management-plugin:1.0.3.RELEASE"
    }
}

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

group = 'io.ai.vivid'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencyManagement {
    imports {
        mavenBom 'com.amazonaws:aws-java-sdk-bom:1.11.228'
    }
}

dependencies {
    compile 'org.springframework.boot:spring-boot-starter-web'
    compile 'org.springframework.boot:spring-boot-starter-websocket'
    compile 'org.springframework.boot:spring-boot-starter-data-jpa'
    compile 'mysql:mysql-connector-java'

    compile 'com.google.code.gson:gson'
    compile 'com.google.guava:guava:20.0'
    compile "com.google.cloud:google-cloud-speech:0.56.0-beta"
    compile 'com.google.apis:google-api-services-dialogflow:v2-rev32-1.25.0'
    compile 'com.google.cloud:google-cloud-dialogflow:0.61.0-alpha'
    compile 'com.google.cloud:google-cloud-texttospeech:0.56.0-beta'
    compile 'com.google.cloud:google-cloud-storage:1.40.0'

    compile 'net.sourceforge.argparse4j:argparse4j:0.8.1'
    compile 'mysql:mysql-connector-java'
    compile 'javax.websocket:javax.websocket-api:1.1'
    compile 'com.nexmo:client:3.7.0'
    compile 'com.amazonaws:aws-java-sdk:1.11.414'

    testCompile('org.springframework.boot:spring-boot-starter-test')
    testCompile group: 'junit', name: 'junit', version: '4.11'
}

以下是我的application.properties文件。

spring.jpa.hibernate.ddl-auto=create
spring.datasource.url=jdbc:mysql://localhost:3306/db
spring.datasource.username=username
spring.datasource.password=password

我在代码中创建的示例实体与示例中提供的示例实体非常相似。我正在使用的Java版本是10。这时,我不确定Spring Boot Java 10(Gradle sourceCompatibility指向1.8。对吗?)

0 个答案:

没有答案