Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Acceing Data with JPA (projectName="gs-accessing-data-jpa")(build=Gradle) #1

Open
sampleCJ opened this issue Oct 19, 2018 · 0 comments

Comments

@sampleCJ
Copy link
Owner

sampleCJ commented Oct 19, 2018

由于个人开发环境与官方文档的差异,因此即使clone项目并注入代码,也有遇上阻碍。


错误报告

在错误报告log.ERROR(...)

2018-10-19 13:43:18.927 ERROR 18992 --- [ main] o.s.boot.SpringApplication : Application run failed

其下首行

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException

划重点

Invocation of init method failed

nested exception is java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException

前者描述问题结果,后者指出可能的错误源JAXBException,即与jaxb-api有关。
这是jdk版本更替所诱发的问题。在jdk8.X至jdk9.X的更新中,jdk9.X为实现模块化,将原本于jdk8.X上仍默认捆绑的jaxb-api剔除其默认路径。
简而言之,我们的配置路径上缺少了jaxb-api的jar包。
若是build with Gradle,只需要在build.gradle文件中添加相应的依赖语句即可。

解决办法
所求依赖语句,应于Maven Repository中搜索jaxb-api可得。点入并选择最新或合适的稳定版本。
在页面下方,会有MavenGradle等的选项卡,选择我们的Gradle,得到依赖语句,

compile group: 'javax.xml.bind', name: 'jaxb-api', version: '2.X.X

我们需要手动添加依赖关系:

  • 在gs-accessing-data-jpa\ ... \build.gradle 文件下
  • 于代码块 dependencies { ... } 中添加该句

具体为

dependencies {
  ...
  compile group: 'javax.xml.bind', name: 'jaxb-api', version: '2.X.X
  ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant