我收到了maven的以下错误:UPDATED
运行应用程序时出错(只需使用数据库设置启动代码)
线程“main”中的异常java.lang.NoClassDefFoundError:org / springframework / context / ApplicationContextInitializer
引起:java.lang.ClassNotFoundException:org.springframework.context.ApplicationContextInitializer
错误安装mvn
[ERROR] initializationError(com.example.polls.PollsApplicationTests)经过的时间:0.005 s<<<错误! org.springframework.beans.BeanInstantiationException:无法实例化[org.springframework.boot.test.context.SpringBootContextLoader]:无法解析的类定义;嵌套异常是java.lang.NoClassDefFoundError:org / springframework / context / ApplicationContextException 引起:java.lang.NoClassDefFoundError:org / springframework / context / ApplicationContextException 引起:java.lang.ClassNotFoundException:org.springframework.context.ApplicationContextException
的pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>polls</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>polls</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.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-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</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.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<!-- For Working with Json Web Tokens (JWT) -->
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.9.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.8</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.1.8</version>
</dependency>
<!-- For Java 8 Date/Time Support -->
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
</dependency>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
唯一的启动代码
package com.example.polls;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class PollsApplication {
public static void main(String[] args) {
SpringApplication.run(PollsApplication.class, args);
}
}
答案 0 :(得分:0)
该错误是由于未拾取spring-boot-starter-parent引起的。尝试摆脱<relativePath/>
,然后从Maven Central Repo中提取该版本。因此<parent>
的定义应该是:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
</parent>
当我尝试不使用Spring Boot父级创建应用程序时遇到或遇到了类似的问题。另一则帖子(对不起,我不能相信)向我指出了此https://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-build-systems.html#using-boot-maven-without-a-parent,它对我有所帮助,但是由于您要使用它,因此问题很简单,就是spring-boot-starter-parent
未被使用