Проблема с ClassNotFoundException в проекте Maven
Мне было поручено завершить проект в рамках моего заявления о приеме на работу. Компания прислала мне установить следующие требования:
- OpenJDK 1.8
- Maven 3.x
- Git 2.x
- MySQL 5.x.
Я пытаюсь запустить приложение со стороны сервера (java), и оно выдает это исключение (возможно, проблема с зависимостью, но я не могу ее найти):
2020-08-30 07: 34: 56.850 ОШИБКА org.springframework.boot.SpringApplication: 858 - Не удалось запустить приложение java.lang.NoClassDefFoundError: org / springframework / boot / bind / RelaxedDataBinder в org.springframework.boot.autoconfigureleConfiguration.En getExcludeAutoConfigurationsProperty (EnableAutoConfigurationImportSelector.java:179) при org.springframework.boot.autoconfigure.EnableAutoConfigurationImportSelector.getExclusions (EnableAutoConfigurationImportSelector.java:172) при org.springframework.boot.autoconfigure.EnableAutoConfigurationImportSelector.selectImports (EnableAutoConfigurationImportSelector.java:87) при org.springframework .context.annotation.ConfigurationClassParser$DefaultDeferredImportSelectorGroup.process(ConfigurationClassParser.java:892) at org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorGrouping.getImports (ConfigurationClassParser.java:878) в org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorGroupingHandler.processGroupImports(ConfigurationClassParser.java:804) at org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorHandler.process (ConfigurationClassParser.java:774) в org.springframework.context.annotation.ConfigurationClassParser.parse (ConfigurationClassParser.java:185) в org.springframework.context.annotation.ConfigationClassProcess (Конфигурация). .springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry (ConfigurationClassPostProcessor.java:232) при org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors (PostProcessorRegistrationDelegate.java:275) при org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors (PostProcessorRegistrationDelegate .java: 95) в org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors (AbstractApplicationContext.java:705) в org.springframework.context.support.AbstractApplicationContext.refresh (Abstrac tApplicationContext.java:531) в org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh (ServletWebServerApplicationContext.java:142) в org.springframework.boot.SpringApplication.boot.SpringApplication.org.spring. .boot.SpringApplication.refreshContext (SpringApplication.java:397) в org.springframework.boot.SpringApplication.run (SpringApplication.java:316) в org.springframework.boot.SpringApplication.run (SpringApplication.java:1260) в org.springframework.java:1260) springframework.boot.SpringApplication.run (SpringApplication.java:1248) в gr.publicsoft.springbootcrud.Application.main (Application.java:12) в java.base / jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (собственный метод) java.base / jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62) в java.base / jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethod.java.Impl.invoke (DelegatingMethod.java.Impl.invoke (DelegatingMethod.java.Impl). think.Method.invoke (Method.java:566) в или g.springframework.boot.devtools.restart.RestartLauncher.run (RestartLauncher.java:49) Вызвано: java.lang.ClassNotFoundException: org.springframework.boot.bind.RelaxedDataBinder в java.baseternal.classk.in .loadClass (BuiltinClassLoader.java:581) в java.base / jdk.internal.loader.ClassLoaders $ AppClassLoader.loadClass (ClassLoaders.java:178) в java.base / java.lang.ClassLoader.loadClass (ClassLoader.java:522 ) ... 26 общих кадров опущены
**Pom.xml(general in project)**
<?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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>gr.publicsoft.springbootcrud</groupId>
<artifactId>spring-boot-crud</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<properties>
<java.version>1.8</java.version>
</properties>
<modules>
<module>springbootcrud-domain</module>
<module>springbootcrud-service</module>
<module>springbootcrud-webapp</module>
</modules>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
**Pom.xml(inside app folder)**
<?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">
<parent>
<artifactId>spring-boot-crud</artifactId>
<groupId>gr.publicsoft.springbootcrud</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>springbootcrud-webapp</artifactId>
<properties>
<java.version>1.8</java.version>
<finalName>${project.artifactId}-${project.version}</finalName> </properties> <profiles> <profile> <id>dev</id> <activation> <activeByDefault>true</activeByDefault> </activation> </profile> </profiles> <dependencies> <dependency> <groupId>gr.publicsoft.springbootcrud</groupId> <artifactId>springbootcrud-service</artifactId> <version>${project.parent.version}</version>
</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-rest</artifactId>
</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-devtools</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
</dependency>
<dependency>
<groupId>eu.bitwalker</groupId>
<artifactId>UserAgentUtils</artifactId>
<version>1.21</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
<version>1.4.1.RELEASE</version>
</dependency>
</dependencies>
<build>
<finalName>${finalName}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<executable>true</executable>
</configuration>
</plugin>
</plugins>
</build>
</project>
Ответы
На самом деле spring-boot-starter-parentсодержат spring-boot-autoconfigure, см.https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-parent/2.3.3.RELEASEдля управляемых зависимостей .
Если вы укажете эту версию специально (то есть есть две разные версии), может возникнуть ошибка.