我尝试学习spring boot,因此我正在编写一个简单的应用程序。目前,其中没有太多代码,只有pom.xml和Main类。这是pom的内容:
<groupId>com.example</groupId>
<artifactId>checkingboot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>checkingboot</name>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
和Main class:
@SpringBootApplication
public class PortalApplication {
public static void main(String[] args) {
SpringApplication.run(PortalApplication.class, args);
}
}
当我在一台计算机上运行代码时,它可以正常工作。但是,在另一种情况下,尝试运行它(通过IntelliJ或使用mvn全新安装)时,我得到
org.springframework.beans.factory.BeanCreationException:创建在类路径资源[org / springframework / boot / autoconfigure / orm / jpa / HibernateJpaAutoConfiguration.class]中定义的名称为'entityManagerFactory'的bean时出错:调用init方法失败;嵌套的异常是java.lang.NoClassDefFoundError:javax / xml / bind / JAXBException ...
我的问题是-为什么会发生这种情况以及如何解决? (我在两台计算机上都安装了当前版本的jdk以及maven的当前版本)
答案 0 :(得分:0)
好吧-显然我对环境有误-在一台机器上(正在工作)我安装了Java 8,而在不工作的机器上却安装了Java 10,因此我在这里得到了问题的答案:
How to resolve java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException in Java 9