SpringBoot项目启动错误,解决方式

Posted 谭宝贵

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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>

  

再重新启动项目,就会发现启动成功啦。

以上是关于SpringBoot项目启动错误,解决方式的主要内容,如果未能解决你的问题,请参考以下文章

Linux 中启动 SpringBoot 项目出现 java.lang.OutOfMemoryError Java heap space 错误

Linux 中启动 SpringBoot 项目出现 java.lang.OutOfMemoryError Java heap space 错误

项目启动报错Failed to configure a DataSource: 'url' attribute is not specified and no embedde(代码片段

SpringBoot启动报错“Consider defining a bean of type ‘xxx.mapper.UserMapper‘ in your configuration.“(代码片段

springboot 使用tomcat 启动 404 问题解决方式

springboot怎么启动项目