问题描述
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