Cannot assign requested address: bind Springboot启动命令-D和--区别

本文详细记录了一次Spring Boot应用在java-jar启动时遇到的'Cannot assign requested address: bind'错误,分析了由于-D参数与--spring.address配置冲突导致的问题。通过将-D改为--修复了这个问题,确保应用能正常启动。同时提供了错误日志及解决方案,对于遇到类似问题的开发者具有参考价值。
摘要由CSDN通过智能技术生成

问题描述

idea启动成功, java -jar启动失败

Cannot assign requested address: bind

org.apache.catalina.LifecycleException: Failed to start component [Connector[HTTP/1.1-10004]]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167) ~[tomcat-embed-core-8.5.28.jar!/:8.5.28]
        at org.apache.catalina.core.StandardService.addConnector(StandardService.java:225) ~[tomcat-embed-core-8.5.28.jar!/:8.5.28]
        at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.addPreviouslyRemovedConnectors(TomcatWebServer.java:255) [spring-boot-2.0.0.RELEASE.jar!/:2.0.0.RELEASE]
        at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.start(TomcatWebServer.java:197) [spring-boot-2.0.0.RELEASE.jar!/:2.0.0.RELEASE]
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.startWebServer(ServletWebServerApplicationContext.java:300) [spring-boot-2.0.0.RELEASE.jar!/:2.0.0.RELEASE]
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.finishRefresh(ServletWebServerApplicationContext.java:162) [spring-boot-2.0.0.RELEASE.jar!/:2.0.0.RELEASE]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:552) [spring-context-5.0.4.RELEASE.jar!/:5.0.4.RELEASE]
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) [spring-boot-2.0.0.RELEASE.jar!/:2.0.0.RELEASE]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:752) [spring-boot-2.0.0.RELEASE.jar!/:2.0.0.RELEASE]
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:388) [spring-boot-2.0.0.RELEASE.jar!/:2.0.0.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:327) [spring-boot-2.0.0.RELEASE.jar!/:2.0.0.RELEASE]
        at com.migu.Application.main(Application.java:17) [classes!/:0.8.10]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_291]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_291]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_291]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_291]
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) [agent-0.8.10.jar:0.8.10]
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) [agent-0.8.10.jar:0.8.10]
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:50) [agent-0.8.10.jar:0.8.10]
        at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51) [agent-0.8.10.jar:0.8.10]
Caused by: org.apache.catalina.LifecycleException: Protocol handler start failed
        at org.apache.catalina.connector.Connector.startInternal(Connector.java:1021) ~[tomcat-embed-core-8.5.28.jar!/:8.5.28]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ~[tomcat-embed-core-8.5.28.jar!/:8.5.28]
        ... 19 common frames omitted
Caused by: java.net.BindException: Cannot assign requested address: bind
        at sun.nio.ch.Net.bind0(Native Method) ~[na:1.8.0_291]
        at sun.nio.ch.Net.bind(Unknown Source) ~[na:1.8.0_291]
        at sun.nio.ch.Net.bind(Unknown Source) ~[na:1.8.0_291]
        at sun.nio.ch.ServerSocketChannelImpl.bind(Unknown Source) ~[na:1.8.0_291]
        at sun.nio.ch.ServerSocketAdaptor.bind(Unknown Source) ~[na:1.8.0_291]
        at org.apache.tomcat.util.net.NioEndpoint.bind(NioEndpoint.java:210) ~[tomcat-embed-core-8.5.28.jar!/:8.5.28]
        at org.apache.tomcat.util.net.AbstractEndpoint.start(AbstractEndpoint.java:1150) ~[tomcat-embed-core-8.5.28.jar!/:8.5.28]
        at org.apache.coyote.AbstractProtocol.start(AbstractProtocol.java:591) ~[tomcat-embed-core-8.5.28.jar!/:8.5.28]
        at org.apache.catalina.connector.Connector.startInternal(Connector.java:1018) ~[tomcat-embed-core-8.5.28.jar!/:8.5.28]
        ... 20 common frames omitted

2022-04-08 13:46:55.625  INFO 15416 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2022-04-08 13:46:55.663  INFO 15416 --- [           main] ConditionEvaluationReportLoggingListener :

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-04-08 13:46:55.669 ERROR 15416 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   :

***************************
APPLICATION FAILED TO START
***************************

Description:

The Tomcat connector configured to listen on port 10004 failed to start. The port may already be in use or the connector may be misconfigured.

Action:

Verify the connector's configuration, identify and stop any process that's listening on port 10004, or configure this application to listen on another port.

原因分析:

原因:
ip配置错误, spring.properties 配置了server.address=ip, 但是命令中又分配了一个ip

-D 是jvm的参数获取的System.getProperty()
– 是springboot参数, 使用applicationContext.getEnvironment().getProperty()获取

所以将-D 修改为 –


解决方案:

# 原本脚本
java -jar .\agent-0.8.10.jar -Dserver.address=10.192.113.195
#修正脚本, 就是-D  改成 --
java -jar .\agent-0.8.10.jar --server.address=10.192.113.195
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值