0


Tc0.Springboot项目启动失败

问题:IDEA调试Springboot项目启动失败:已与地址为 ‘‘127.0.0.1:12574’,传输: ‘套接字’’ 的目标虚拟机断开连接

一、现象描述

  • IDE(IDEA或者Eclipse)调试模式

博主使用的是IDEA 2023社区版:已与地址为 ‘‘127.0.0.1:12574’,传输: ‘套接字’’ 的目标虚拟机断开连接

或者

Disconnected from the target VM, address: ‘127.0.0.1:56065’, transport: ‘socket’

二、问题分析

网络常见问题原因:

  1. 缺少依赖项
  2. java和tomcat版本不匹配
  3. 端口占用
  4. 使用maven打包程序
  5. (重要)此问题还有可能是以下几个问题产生,导致项目运行失败。需进一步排查。

总结概括就是,检查jar包冲突与缺少的依赖项目。

三、解决方案

缺少依赖项解决方法:

首先编辑pom文件,父级依赖及

spring-web

启动器依赖

<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><!--SpringBoot版本--><version>2.6.3</version></parent><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency></dependencies>

导入依赖 ,加载maven更改。

java和tomcat版本不匹配

检查版本

java -version
javac -version
端口占用
netstat-an|grep 端口号

如有有占用,杀死相应进程

使用maven打包程序
java-jar D:\Work\Code\java\demo\target\demo-0.0.1-SNAPSHOT.jar

有些时候,idea启动不了,但是命令行可以启动

问题:Springboot项目打包出错:Please refer to XXX\target\surefire-reports for the individual test results

一、现象描述

详细提示

Please refer toD:\Work\java\demo\target\surefire-reports for the individual test results.
Please refer todump files (if any exist)[date].dump,[date]-jvmRun[N].dump and [date].dumpstream.

二、问题分析

出错的原因,是该项目存在一些异常错误。

三、解决方案

方法一:依次排查pom依赖项,找到项目出现了异常。

方法二:使用maven的配置来将测试错误忽略掉。

方法三: java/demo/pom.xml文件中,添加属性,并设置为true。然后刷新pom.xml。

    <properties>
        <java.version>17</java.version>
        <skipTests>true</skipTests>
    </properties>

此方法虽然可以完成打包,但是如果包还是有错,执行时还是会出错。具体参考下面的问题。

问题:Springboot项目调试出错java.lang.NoClassDefFoundError: javax/servlet/ServletRequest

一、现象描述

在上面的打包出错的时候,调试会发生如下错误:

java.lang.NoClassDefFoundError: javax/servlet/ServletRequest
    at org.springframework.web.context.support.WebApplicationContextUtils.registerWebApplicationScopes(WebApplicationContextUtils.java:195)~[spring-web-5.3.15.jar:5.3.15]
    at org.springframework.web.context.support.WebApplicationContextUtils.registerWebApplicationScopes(WebApplicationContextUtils.java:174)~[spring-web-5.3.15.jar:5.3.15]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.registerWebApplicationScopes(ServletWebServerApplicationContext.java:254)~[spring-boot-3.2.0.jar:3.2.0]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.postProcessBeanFactory(ServletWebServerApplicationContext.java:140)~[spring-boot-3.2.0.jar:3.2.0]
    at org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext.postProcessBeanFactory(AnnotationConfigServletWebServerApplicationContext.java:200)~[spring-boot-3.2.0.jar:3.2.0]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:593)~[spring-context-6.1.1.jar:6.1.1]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146)~[spring-boot-3.2.0.jar:3.2.0]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:753)~[spring-boot-3.2.0.jar:3.2.0]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:455)~[spring-boot-3.2.0.jar:3.2.0]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:323)~[spring-boot-3.2.0.jar:3.2.0]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1342)~[spring-boot-3.2.0.jar:3.2.0]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1331)~[spring-boot-3.2.0.jar:3.2.0]
    at com.example.demo.DemoApplication.main(DemoApplication.java:10)~[classes/:na]Caused by:java.lang.ClassNotFoundException:javax.servlet.ServletRequest
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)~[na:na]
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)~[na:na]
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)~[na:na]...13 common frames omitted

二、问题分析

即使使用上面的方法打包成功,执行时仍然会报这个错。

此错误原始意思时jvm运行找不到这个类。

三、解决方案

编译时缺少或者运行时缺少,运行缺少主要可能是配置不对。

使用maven分析依赖关系。查看具体冲突的依赖。

<dependency>
  <groupId>javax.servlet</groupId>
  <artifactId>javax.servlet-api</artifactId>
  <version>3.1.0</version>
</dependency>

问题:Springboot项目maven出错

一、现象描述

运行重新加载所有Maven项目,报错如下

无法解析插件 org.apache.maven.plugins:maven-site-plugin:3.12.1

尝试使用 -U 标记(强制更新快照)运行 Maven 导入

二、问题分析

不影响打包

三、解决方案

无。

问题:使用npm安装axios之后出错

一、现象描述

 ERROR  Failed to compile with 1 errors                                                                          下午1:06:04

 error  in ./node_modules/axios/lib/platform/index.js

Module parse failed: Unexpected token (5:2)

二、问题分析

这个错误也有很多情况,其中之一:npm安装了一个包,然后在导入的时候报这个语法错。

三、解决方案

npm list 查看的包名       #查看安装版本npm view 查看的包名 version #查看最新版本npm view 查看的包名 versions    #这个会查到npm服务器上对应查询包的版本所有信息npm uninstall axios  #卸载安装的版本    npminstall [email protected] --save#下载对应的版本
标签: spring boot 后端 java

本文转载自: https://blog.csdn.net/xinqingwuji/article/details/135015776
版权归原作者 道格拉斯范朋克 所有, 如有侵权,请联系我们删除。

“Tc0.Springboot项目启动失败”的评论:

还没有评论