zoukankan      html  css  js  c++  java
  • 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>
    

      

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

  • 相关阅读:
    SMTP协议简介
    Debian
    TCP/IP协议基础
    CentOS(Community ENTerprise Operating System)
    IO
    【备忘】Windows网络命令行操作
    repeater中绑定dropdownlist事件
    MultipleActiveResultSets
    .NET UEditor使用方法
    Asp.net中时间格式化的几种方法
  • 原文地址:https://www.cnblogs.com/eathertan/p/12727197.html
Copyright © 2011-2022 走看看