• Unregistering JMX-exposed beans on shutdown


    🌷🍁 博主猫头虎 带您 Go to New World.✨🍁
    🦄 博客首页——猫头虎的博客🎐
    🐳《面试题大全专栏》 文章图文并茂🦕生动形象🦖简单易学!欢迎大家来踩踩~🌺
    🌊 《IDEA开发秘籍专栏》学会IDEA常用操作,工作效率翻倍~💐
    🌊 《100天精通Golang(基础入门篇)》学会Golang语言,畅玩云原生,走遍大小厂~💐

    🪁🍁 希望本文能够给您带来一定的帮助🌸文章粗浅,敬请批评指正!🍁🐥

    解决Spring Boot应用启动及404问题

    在开发和部署Spring Boot应用程序时,遇到问题是很常见的。本篇博客将为您介绍一种常见的启动问题以及对应的解决方案。我们将首先通过错误信息来了解问题,然后逐步引入解决方案,并对其进行详细的讲解。

    摘要

    本文将探讨在启动Spring Boot应用程序时出现的两个常见问题:一是启动成功但无法访问接口,返回404错误;二是应用启动失败。我们将通过具体的错误信息和解决方案来说明如何解决这些问题,以及如何正确配置应用以避免类似问题。

    引言

    Spring Boot作为一种快速开发框架,大大提高了Java应用程序的开发效率。然而,在开发和部署过程中,您可能会遇到各种问题。这些问题可能涉及应用的配置、依赖项、服务器问题等。本篇博客将关注两个常见的问题:启动成功但返回404错误,以及应用启动失败。我们将逐步介绍这些问题的背景、原因和解决方案。

    错误信息:

    在这里插入图片描述

    
    D:\Java\corretto-1.8.0_342\bin\java.exe -XX:TieredStopAtLevel=1 -noverify -Dspring.output.ansi.enabled=always -Dcom.sun.management.jmxremote -Dspring.jmx.enabled=true -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true -javaagent:D:\IDEA\apps\IDEA-U\ch-0\222.4345.14\lib\idea_rt.jar=54850 
    
      .   ____          _            __ _ _
     /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
    ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
     \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
      '  |____| .__|_| |_|_| |_\__, | / / / /
     =========|_|==============|___/=/_/_/_/
     :: Spring Boot ::        (v2.7.2)
    
    2022-11-01 09:19:00  [INFO]  org.springframework.boot.StartupInfoLogger:48  : Starting ApplicationKt on OAK with PID 20788 (E:\Project-Code\OutsideApi\build\classes\kotlin\main started by DELL in E:\Project-Code\OutsideApi) 
    2022-11-01 09:19:00  [INFO]  org.springframework.boot.SpringApplication:593  : No active profile set, falling back to default profiles: default 
    2022-11-01 09:19:00  [INFO]  org.springframework.context.support.AbstractApplicationContext:583  : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@7ee955a8: startup date [Tue Nov 01 09:19:00 CST 2022]; root of context hierarchy 
    2022-11-01 09:19:01  [INFO]  org.springframework.jmx.export.MBeanExporter:431  : Registering beans for JMX exposure on startup 
    2022-11-01 09:19:01  [INFO]  org.springframework.boot.StartupInfoLogger:57  : Started JoySpaceApplicationKt in 1.018 seconds (JVM running for 1.513) 
    2022-11-01 09:19:01  [INFO]  org.springframework.context.support.AbstractApplicationContext:984  : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@7ee955a8: startup date [Tue Nov 01 09:19:00 CST 2022]; root of context hierarchy 
    2022-11-01 09:19:01  [INFO]  org.springframework.jmx.export.MBeanExporter:449  : Unregistering JMX-exposed beans on shutdown 
    
    Process finished with exit code 0
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20

    网上的解决方案:

    引入Tomcat

    
    	implementation("org.springframework.boot:spring-boot-starter-tomcat:2.7.2")
    
    
    
    • 1
    • 2
    • 3
    • 4

    启动成功

    在这里插入图片描述

    ,结果又会出现另一个问题,访问所有接口都变成404

    
    HTTP/1.1 404 
    Content-Type: text/html;charset=utf-8
    Content-Language: en
    Content-Length: 1086
    Date: Tue, 01 Nov 2022 01:28:17 GMT
    
    
    
    HTTP Status 404 – Not Found
        
    
    

    HTTP Status 404 – Not Found


    "line"
    />

    Type Status Report

    Message /photo/takeCutPic

    Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.


    "line"/>

    Apache Tomcat/8.5.23

    Response file saved. > 2022-11-01T092817.404.html Response code: 404; Time: 42ms (42 ms); Content length: 1082 bytes (1.08 kB)
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78

    完美解决方案:

    缺失: org.springframework.boot:spring-boot-starter-web:2.7.2 依赖
    在这里插入图片描述

    
                org.springframework.boot
                spring-boot-starter-web
     
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    
    	implementation("org.springframework.boot:spring-boot-starter-web:2.7.2")
    
    
    • 1
    • 2
    • 3

    问题一:启动成功但返回404错误

    错误信息

    404 Error

    分析

    当您启动应用程序后,您可能会遇到一种情况,即应用程序启动成功,但当尝试访问接口时,会返回404错误。这意味着服务器找不到请求的资源,导致访问失败。

    解决方案

    要解决这个问题,您需要检查应用程序的依赖项配置。很可能是因为缺少了spring-boot-starter-web依赖,导致应用程序无法正确处理HTTP请求。您可以通过在pom.xml中添加以下依赖项来解决这个问题:

    <dependency>
        <groupId>org.springframework.bootgroupId>
        <artifactId>spring-boot-starter-webartifactId>
    dependency>
    
    • 1
    • 2
    • 3
    • 4

    或者,如果您使用的是Gradle,可以通过以下方式引入依赖:

    implementation("org.springframework.boot:spring-boot-starter-web:2.7.2")
    
    • 1

    这将确保应用程序具备处理HTTP请求的能力,从而解决404错误问题。

    问题二:应用启动失败

    错误信息

    应用启动失败

    分析

    在启动Spring Boot应用程序时,您可能会遇到应用程序无法启动的情况。这可能涉及到多种问题,如缺少依赖、配置错误、端口被占用等。

    解决方案

    如果应用程序启动失败,首先要检查日志中的错误信息,以了解具体的问题。在这个例子中,似乎应用程序缺少了Tomcat容器。为了解决这个问题,您需要引入spring-boot-starter-tomcat依赖:

    <dependency>
        <groupId>org.springframework.bootgroupId>
        <artifactId>spring-boot-starter-tomcatartifactId>
    dependency>
    
    • 1
    • 2
    • 3
    • 4

    或者,在Gradle中:

    implementation("org.springframework.boot:spring-boot-starter-tomcat:2.7.2")
    
    • 1

    这将引入Tomcat容器,并使应用程序能够在其中运行。如果有其他依赖关系或配置问题,您可以根据错误信息逐步排查并解决。

    总结

    在开发和部署Spring Boot应用程序时,遇到问题是正常的。本篇博客介绍了两个常见的问题:启动成功但返回404错误,以及应用启动失败。对于第一个问题,问题可能是缺少spring-boot-starter-web依赖,解决方案是引入该依赖。对于第二个问题,问题可能是缺少Tomcat容器,解决方案是引入spring-boot-starter-tomcat依赖。通过理解这些问题的背景、原因和解决方案,您将能够更好地处理类似问题,并确保您的Spring Boot应用程序正常运行。

    原创声明

    ======= ·

    • 原创作者: 猫头虎

    作者wx: [ libin9iOak ]

    学习复习

    本文为原创文章,版权归作者所有。未经许可,禁止转载、复制或引用。

    作者保证信息真实可靠,但不对准确性和完整性承担责任

    未经许可,禁止商业用途。

    如有疑问或建议,请联系作者。

    感谢您的支持与尊重。

    点击下方名片,加入IT技术核心学习团队。一起探索科技的未来,共同成长。

  • 相关阅读:
    kafka如何保证消息顺序性?
    【小尘送书-第八期】《小团队管理:如何轻松带出1+1>2的团队》
    18650锂电池参数、充放电时间计算详解
    VR+中医骨伤学仿真情景实训教学|英途信息
    软件包 - 笔记
    Handler 原理
    根据format索引值返回括号中的参数
    Spring MVC框架中Formatter数据格式化的相关说明
    说一下 ArrayList 和 LinkedList 的区别?
    “PairElimination“ app Tech Support(URL)
  • 原文地址:https://blog.csdn.net/qq_44866828/article/details/127627488