我创建了一个spring应用程序,并使用hibernate从mysql数据库生成java类。之后,我想用这个类来实现存储库,但我遇到了一个问题:
org.springframework.beans.factory.beancreationexception:创建名为“entitymanagerfactory”的bean时出错,该bean在类路径资源[org/springframework/boot/autoconfigure/orm/jpa/hibernatejpaconfiguration.class]中定义:调用init方法失败;嵌套的异常是java.lang.noclassdeffounderror:javax/xml/bind/jaxbeException
这是我的build.gradle文件
plugins {
id 'org.springframework.boot' version '2.4.4'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
id "org.hibernate.gradle.tools" version "1.2.5"
}
group = 'it.unisalento'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'mysql:mysql-connector-java'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.javassist:javassist:3.27.0-GA'
compile 'org.hibernate:hibernate-core:5.2.11.Final'
compile 'org.hibernate:hibernate-entitymanager:5.2.11.Final'
compile 'mysql:mysql-connector-java'
compile 'org.apache.commons:commons-dbcp2:2.0.1'
}
test {
useJUnitPlatform()
}
import org.hibernate.gradle.tools.*
database{
catalog = ["myalertdb": new Schema()]
basePackage = "it.unisalento.myalertapp.app.domain"
port = 3306
url = "jdbc:mysql://127.0.0.1/myalertdb?serverTimezone=GMT"
user = "root"
password = "database123"
dialect = "org.hibernate.dialect.MySQLDialect"
driver = "com.mysql.cj.jdbc.Driver"
}
1条答案
按热度按时间c6ubokkw1#
出现这种情况的一个原因是您运行的是Java9或更高版本。那你需要加上
jaxb-api.jar
到你的类路径。如果您运行的是maven,您可以通过将以下内容添加到pom.xml中来完成此操作:请看https://www.jesperdj.com/2018/09/30/jaxb-on-java-9-10-11-and-beyond/ 更多细节。