• 本地启动springboot项目失败端口问题


    异常关键字:

    Cannot assign requested address: bind

    排查结果

    配置了环境变量【SERVER_ADDRESS】
    本机环境变量
    网上搜了有的回答是端口占用,是不对的,端口占用的异常是这个【Web server failed to start. Port 8282 was already in use.】

    解决办法

    第一种:删除相关环节变量
    第二种:增加配置server.address=localhost。需要注意的是,如果是使用局域网IP访问需要将localhost改成对应的IP

    排查结果非常曲折,提供关键字供参考

    • org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory#getWebServer
    • org.springframework.boot.context.properties.bind.Binder#bind(org.springframework.boot.context.properties.source.ConfigurationPropertyName, org.springframework.boot.context.properties.bind.Bindable, org.springframework.boot.context.properties.bind.BindHandler, org.springframework.boot.context.properties.bind.Binder.Context, boolean, boolean)
    • org.springframework.boot.context.properties.bind.JavaBeanBinder#bind(org.springframework.boot.context.properties.bind.JavaBeanBinder.BeanSupplier, org.springframework.boot.context.properties.bind.DataObjectPropertyBinder, org.springframework.boot.context.properties.bind.JavaBeanBinder.BeanProperty)
    • 条件断点 “address”.equals(propertyName)
      在这里插入图片描述
    • org.springframework.boot.context.properties.bind.Binder#findProperty
      在这里插入图片描述

    到此是找到位置了

    我的天,一个早上,终于找到位置了,但是还是不知道哪里的问题,执行如下代码发现,getenv这里有,因为里面有JAVA_HOME,那还我配置的环境变量。果然是他。
    这台电脑不是全新的,不知道上个使用者为什么要配置这个,也算是问题找到了,删了这个,完成。

    
        @Test
        public void testHost() {
            System.getProperties().forEach((k, v) -> System.out.println(k + " ==> " + v));
        }
        @Test
        public void testEnv() {
            System.getenv().forEach((k, v) -> System.out.println(k + " ==> " + v));
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    异常堆栈:

    
    Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
    2022-11-29 13:57:59.317 ERROR 1776 --- [           main] o.s.boot.SpringApplication               : Application run failed
    
    org.springframework.context.ApplicationContextException: Failed to start bean 'webServerStartStop'; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat server
    	at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:181) ~[spring-context-5.3.21.jar:5.3.21]
    	at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:54) ~[spring-context-5.3.21.jar:5.3.21]
    	at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:356) ~[spring-context-5.3.21.jar:5.3.21]
    	at java.base/java.lang.Iterable.forEach(Iterable.java:75) ~[na:na]
    	at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:155) ~[spring-context-5.3.21.jar:5.3.21]
    	at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:123) ~[spring-context-5.3.21.jar:5.3.21]
    	at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:935) ~[spring-context-5.3.21.jar:5.3.21]
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:586) ~[spring-context-5.3.21.jar:5.3.21]
    	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147) ~[spring-boot-2.7.3.jar:2.7.3]
    	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:734) ~[spring-boot-2.7.3.jar:2.7.3]
    	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408) ~[spring-boot-2.7.3.jar:2.7.3]
    	at org.springframework.boot.SpringApplication.run(SpringApplication.java:308) ~[spring-boot-2.7.3.jar:2.7.3]
    	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306) ~[spring-boot-2.7.3.jar:2.7.3]
    	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295) ~[spring-boot-2.7.3.jar:2.7.3]
    	at com.org.swg.SwgApplication.main(SwgApplication.java:15) ~[classes/:na]
    Caused by: org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat server
    	at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.start(TomcatWebServer.java:229) ~[spring-boot-2.7.3.jar:2.7.3]
    	at org.springframework.boot.web.servlet.context.WebServerStartStopLifecycle.start(WebServerStartStopLifecycle.java:43) ~[spring-boot-2.7.3.jar:2.7.3]
    	at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:178) ~[spring-context-5.3.21.jar:5.3.21]
    	... 14 common frames omitted
    Caused by: java.lang.IllegalArgumentException: standardService.connector.startFailed
    	at org.apache.catalina.core.StandardService.addConnector(StandardService.java:238) ~[tomcat-embed-core-9.0.65.jar:9.0.65]
    	at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.addPreviouslyRemovedConnectors(TomcatWebServer.java:282) ~[spring-boot-2.7.3.jar:2.7.3]
    	at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.start(TomcatWebServer.java:213) ~[spring-boot-2.7.3.jar:2.7.3]
    	... 16 common frames omitted
    Caused by: org.apache.catalina.LifecycleException: Protocol handler start failed
    	at org.apache.catalina.connector.Connector.startInternal(Connector.java:1077) ~[tomcat-embed-core-9.0.65.jar:9.0.65]
    	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.65.jar:9.0.65]
    	at org.apache.catalina.core.StandardService.addConnector(StandardService.java:234) ~[tomcat-embed-core-9.0.65.jar:9.0.65]
    	... 18 common frames omitted
    Caused by: java.net.BindException: Cannot assign requested address: bind
    	at java.base/sun.nio.ch.Net.bind0(Native Method) ~[na:na]
    	at java.base/sun.nio.ch.Net.bind(Net.java:461) ~[na:na]
    	at java.base/sun.nio.ch.Net.bind(Net.java:453) ~[na:na]
    	at java.base/sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:227) ~[na:na]
    	at org.apache.tomcat.util.net.NioEndpoint.initServerSocket(NioEndpoint.java:275) ~[tomcat-embed-core-9.0.65.jar:9.0.65]
    	at org.apache.tomcat.util.net.NioEndpoint.bind(NioEndpoint.java:230) ~[tomcat-embed-core-9.0.65.jar:9.0.65]
    	at org.apache.tomcat.util.net.AbstractEndpoint.bindWithCleanup(AbstractEndpoint.java:1227) ~[tomcat-embed-core-9.0.65.jar:9.0.65]
    	at org.apache.tomcat.util.net.AbstractEndpoint.start(AbstractEndpoint.java:1313) ~[tomcat-embed-core-9.0.65.jar:9.0.65]
    	at org.apache.coyote.AbstractProtocol.start(AbstractProtocol.java:614) ~[tomcat-embed-core-9.0.65.jar:9.0.65]
    	at org.apache.catalina.connector.Connector.startInternal(Connector.java:1074) ~[tomcat-embed-core-9.0.65.jar:9.0.65]
    	... 20 common frames omitted
    
    
    Process finished with exit code 1
    
    
    • 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
  • 相关阅读:
    【C++】---了解string类
    thymeleaf在网页中上传文件
    Qt软键盘使用和修改软键盘参数 支持中文
    深度学习语法笔记(一)——loss.item() -numpy() - unsqueeze() -MSELOSS()
    5个前端练手项目(html css js canvas)
    Javascript 手写 LRU 算法
    实战模拟│JWT 登录认证
    如何用 Docker 安装运行 mysql?
    JAVA计算机毕业设计牙科诊所信息化管理平台Mybatis+系统+数据库+调试部署
    什么是无线接入点 Access point?
  • 原文地址:https://blog.csdn.net/o544033135/article/details/128097006