SpringBoot項目啟動錯誤,解決方式


SpringBoot項目啟動錯誤,錯誤信息如下

Connected to the target VM, address: '127.0.0.1:53101', transport: 'socket'
Exception in thread "main" 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:116)
at org.springframework.boot.convert.ApplicationConversionService.configure(ApplicationConversionService.java:100)
at org.springframework.boot.convert.ApplicationConversionService.<init>(ApplicationConversionService.java:61)
at org.springframework.boot.convert.ApplicationConversionService.<init>(ApplicationConversionService.java:54)
at org.springframework.boot.convert.ApplicationConversionService.getSharedInstance(ApplicationConversionService.java:80)
at org.springframework.boot.SpringApplication.configureEnvironment(SpringApplication.java:478)
at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:343)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:308)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215)
at com.course.application.Application.main(Application.java:11)
Caused by: java.lang.ClassNotFoundException: org.springframework.util.unit.DataSize
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 14 more
Disconnected from the target VM, address: '127.0.0.1:53101', transport: 'socket'

Process finished with exit code 1

解決方式:
是因為指定父類的版本號 和 下面的depenency 版本不同。

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

 

但是我其他的Springboot 的依賴,我又給他指定了其他的版本, <version>2.2.5.RELEASE</version>,如下。

<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
<version>2.2.5.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.2.5.RELEASE</version>
</dependency>

  

這樣是錯誤的,導致兩個版本不一致。

此時可以不指定版本,因為parent已經指定了版本,直接繼承父類的版本即可

<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

  

再重新啟動項目,就會發現啟動成功啦。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM