java.lang.NoClassDefFoundError:运行Spring Boot项目时org / springframework / util / unit / DataSize

时间:2018-12-03 12:20:03

标签: spring-boot

将spring-boot版本更改为2.0.1.RELEASE后,在运行spring boot项目时出现此错误。我只是从2.0.3.RELEASE更改版本

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <version>2.1.0.RELEASE</version>
    </dependency>

[DEV: 2018-Dec-03 17:35:10,523][ERROR][main      ]Application run failed
java.lang.NoClassDefFoundError: org/springframework/util/unit/DataSize
at org.springframework.boot.convert.StringToDataSizeConverter.getConvertibleTypes(StringToDataSizeConverter.java:40)
at org.springframework.core.convert.support.GenericConversionService$Converters.add(GenericConversionService.java:507)
at org.springframework.core.convert.support.GenericConversionService.addConverter(GenericConversionService.java:105)
at org.springframework.boot.convert.ApplicationConversionService.addApplicationConverters(ApplicationConversionService.java:107)
at org.springframework.boot.convert.ApplicationConversionService.configure(ApplicationConversionService.java:91)
at org.springframework.boot.convert.ApplicationConversionService.<init>(ApplicationConversionService.java:52)
at org.springframework.boot.convert.ApplicationConversionService.<init>(ApplicationConversionService.java:45)
at org.springframework.boot.convert.ApplicationConversionService.getSharedInstance(ApplicationConversionService.java:71)
at org.springframework.boot.SpringApplication.configureEnvironment(SpringApplication.java:486)
at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:346)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:306)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248)
at org.onap.universalvesadapter.Application.main(Application.java:29)
Caused by: java.lang.ClassNotFoundException: org.springframework.util.unit.DataSize
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357) 

3 个答案:

答案 0 :(得分:7)

这个问题为我解决了,因为我的POM.xml错误地在属性标签中包含了spring.version。

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.1.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>

<properties>
    <java.version>1.8</java.version>
    <kotlin.version>1.2.71</kotlin.version>
    <!-- <spring.version>5.0.6.RELEASE</spring.version> -->
</properties>

答案 1 :(得分:0)

根据Spring Framework Versions

JDK版本范围

  • Spring Framework 5.1.x:JDK 8-12
  • Spring Framework 5.0.x:JDK 8-10

因此,如果您使用的是JDK 11,则在pom.xml中定义:

<spring-framework.version>5.0.x.RELEASE</spring-framework.version>

<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-webmvc</artifactId>
  <version>${spring-framework.version}</version>
</dependency>

然后发生了这样的问题。当然,您可以使用其他名称定义spring-framework.version,甚至直接对其进行注释,以便绕过此版本检查。但是不推荐。

解决方案:

选择合适的spring-framework版本以匹配您的JDK。

答案 2 :(得分:0)

将spring 4.x与spring-boot 2.1.x结合使用也可能导致这种情况。 确保spring-core的{​​{1}}依赖项与(父)spring-boot中的spring-core声明具有相同的版本。