ClassNotFoundException在Maven项目中的问题

huangapple go评论123阅读模式
英文:

ClassNotFoundException issue in Maven project

问题

我被指派完成一个作为申请工作的一部分的项目。公司派我安装以下要求:

  • 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 at
org.springframework.boot.autoconfigure.EnableAutoConfigurationImportSelector.getExcludeAutoConfigurationsProperty(EnableAutoConfigurationImportSelector.java:179)
...

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">
     ...
</project>

Pom.xml(app 文件夹内部的部分)

<?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">
    ...
</project>

(以上是您提供的内容的翻译部分,不包含额外的回答或内容。)

英文:

I was assigned to complete a project as part of my application for a job. The company send me to install the following requirements:

  • OpenJDK 1.8
  • Maven 3.x
  • Git 2.x
  • MySQL 5.x.

I am trying to run the app from the server side (java) and it throws this exception (probably a dependency issue but i can't find it):

> 2020-08-30 07:34:56.850 ERROR
> org.springframework.boot.SpringApplication:858 - Application run
> failed java.lang.NoClassDefFoundError:
> org/springframework/boot/bind/RelaxedDataBinder at
> org.springframework.boot.autoconfigure.EnableAutoConfigurationImportSelector.getExcludeAutoConfigurationsProperty(EnableAutoConfigurationImportSelector.java:179)
> at
> org.springframework.boot.autoconfigure.EnableAutoConfigurationImportSelector.getExclusions(EnableAutoConfigurationImportSelector.java:172)
> at
> org.springframework.boot.autoconfigure.EnableAutoConfigurationImportSelector.selectImports(EnableAutoConfigurationImportSelector.java:87)
> at
> org.springframework.context.annotation.ConfigurationClassParser$DefaultDeferredImportSelectorGroup.process(ConfigurationClassParser.java:892)
> at
> org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorGrouping.getImports(ConfigurationClassParser.java:878)
> at
> org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorGroupingHandler.processGroupImports(ConfigurationClassParser.java:804)
> at
> org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorHandler.process(ConfigurationClassParser.java:774)
> at
> org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:185)
> at
> org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:315)
> at
> org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:232)
> at
> org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:275)
> at
> org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:95)
> at
> org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:705)
> at
> org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:531)
> at
> org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142)
> at
> org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775)
> at
> org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
> at
> org.springframework.boot.SpringApplication.run(SpringApplication.java:316)
> at
> org.springframework.boot.SpringApplication.run(SpringApplication.java:1260)
> at
> org.springframework.boot.SpringApplication.run(SpringApplication.java:1248)
> at gr.publicsoft.springbootcrud.Application.main(Application.java:12)
> at
> java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native
> Method) at
> java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> at
> java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.base/java.lang.reflect.Method.invoke(Method.java:566) at
> org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
> Caused by: java.lang.ClassNotFoundException:
> org.springframework.boot.bind.RelaxedDataBinder at
> java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
> at
> java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
> at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
> ... 26 common frames omitted

**Pom.xml(general in project)**
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot;
     xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
     xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven- 
 4.0.0.xsd&quot;&gt;
 &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;

&lt;parent&gt;
    &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
    &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
    &lt;version&gt;2.1.4.RELEASE&lt;/version&gt;
    &lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
&lt;/parent&gt;

&lt;groupId&gt;gr.publicsoft.springbootcrud&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-crud&lt;/artifactId&gt;
&lt;packaging&gt;pom&lt;/packaging&gt;
&lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;

&lt;properties&gt;
    &lt;java.version&gt;1.8&lt;/java.version&gt;
&lt;/properties&gt;

&lt;modules&gt;
    &lt;module&gt;springbootcrud-domain&lt;/module&gt;
    &lt;module&gt;springbootcrud-service&lt;/module&gt;
    &lt;module&gt;springbootcrud-webapp&lt;/module&gt;
&lt;/modules&gt;

&lt;build&gt;
    &lt;plugins&gt;
        &lt;plugin&gt;
            &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
            &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
            &lt;configuration&gt;
                &lt;source&gt;1.8&lt;/source&gt;
                &lt;target&gt;1.8&lt;/target&gt;
            &lt;/configuration&gt;
        &lt;/plugin&gt;
    &lt;/plugins&gt;
&lt;/build&gt;

&lt;/project&gt;

**Pom.xml(inside app folder)**
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot;
     xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
     xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven- 
4.0.0.xsd&quot;&gt;
&lt;parent&gt;
    &lt;artifactId&gt;spring-boot-crud&lt;/artifactId&gt;
    &lt;groupId&gt;gr.publicsoft.springbootcrud&lt;/groupId&gt;
    &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
&lt;/parent&gt;
&lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;

&lt;artifactId&gt;springbootcrud-webapp&lt;/artifactId&gt;



&lt;properties&gt;
    &lt;java.version&gt;1.8&lt;/java.version&gt;
    &lt;finalName&gt;${project.artifactId}-${project.version}&lt;/finalName&gt;
&lt;/properties&gt;

&lt;profiles&gt;
    &lt;profile&gt;
        &lt;id&gt;dev&lt;/id&gt;
        &lt;activation&gt;
            &lt;activeByDefault&gt;true&lt;/activeByDefault&gt;
        &lt;/activation&gt;
    &lt;/profile&gt;
&lt;/profiles&gt;

&lt;dependencies&gt;

    &lt;dependency&gt;
        &lt;groupId&gt;gr.publicsoft.springbootcrud&lt;/groupId&gt;
        &lt;artifactId&gt;springbootcrud-service&lt;/artifactId&gt;
        &lt;version&gt;${project.parent.version}&lt;/version&gt;
    &lt;/dependency&gt;

    &lt;dependency&gt;
        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
        &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
        &lt;artifactId&gt;spring-boot-starter-data-rest&lt;/artifactId&gt;
    &lt;/dependency&gt;

    &lt;dependency&gt;
        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
        &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
        &lt;scope&gt;test&lt;/scope&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
        &lt;artifactId&gt;spring-boot-devtools&lt;/artifactId&gt;
        &lt;optional&gt;true&lt;/optional&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;org.liquibase&lt;/groupId&gt;
        &lt;artifactId&gt;liquibase-core&lt;/artifactId&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;eu.bitwalker&lt;/groupId&gt;
        &lt;artifactId&gt;UserAgentUtils&lt;/artifactId&gt;
        &lt;version&gt;1.21&lt;/version&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
        &lt;artifactId&gt;spring-boot-autoconfigure&lt;/artifactId&gt;
        &lt;version&gt;1.4.1.RELEASE&lt;/version&gt;
    &lt;/dependency&gt;
&lt;/dependencies&gt;

&lt;build&gt;
    &lt;finalName&gt;${finalName}&lt;/finalName&gt;
    &lt;plugins&gt;
        &lt;plugin&gt;
            &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
            &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
            &lt;configuration&gt;
                &lt;executable&gt;true&lt;/executable&gt;
            &lt;/configuration&gt;
        &lt;/plugin&gt;
    &lt;/plugins&gt;
&lt;/build&gt;

&lt;/project&gt;

答案1

得分: 1

实际上,spring-boot-starter-parent 包含了 spring-boot-autoconfigure,请参阅<https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-parent/2.3.3.RELEASE> 查看托管的依赖项

如果您明确指定了这个版本(也就是说,有两个不同的版本),可能会出现错误。

英文:

Actually the spring-boot-starter-parent contain spring-boot-autoconfigure,see <https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-parent/2.3.3.RELEASE> for Managed Dependencies .

If you specify this version specifically (that is, there are two different versions), an error may occur.

huangapple
  • 本文由 发表于 2020年8月30日 12:46:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/63654044.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定