gpt4 book ai didi

java - Spring Boot 无法监听端口

转载 作者:太空宇宙 更新时间:2023-11-04 11:27:59 25 4
gpt4 key购买 nike

我使用的是 MacOS Sierra。我使用 Springboot-cli 生成一个空白项目并添加一个基本的 RESTController:

@GetMapping("/")
public Object index(){
return "hello world";
}

我运行了该项目。控制台中的输出看起来一切都很好:

  .   ____          _            __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.5.3.RELEASE)

2017-05-23 23:54:19.470 INFO 3776 --- [ main] com.bonc.smallETL.ETLApp : Starting ETLApp on SLs-Mac.local with PID 3776 (/Users/liuxiaoyang/Desktop/sourceCode/smallETL/smalletl-back/target/classes started by liuxiaoyang in /Users/liuxiaoyang/Desktop/sourceCode/smallETL/smalletl-back)
2017-05-23 23:54:19.473 INFO 3776 --- [ main] com.bonc.smallETL.ETLApp : No active profile set, falling back to default profiles: default
2017-05-23 23:54:19.571 INFO 3776 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@2805c96b: startup date [Tue May 23 23:54:19 CST 2017]; root of context hierarchy
2017-05-23 23:54:21.126 INFO 3776 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 9999 (http)
2017-05-23 23:54:21.142 INFO 3776 --- [ main] o.apache.catalina.core.StandardService : Starting service Tomcat
2017-05-23 23:54:21.143 INFO 3776 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.14
2017-05-23 23:54:21.263 INFO 3776 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2017-05-23 23:54:21.264 INFO 3776 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1699 ms
2017-05-23 23:54:21.401 INFO 3776 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2017-05-23 23:54:21.405 INFO 3776 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2017-05-23 23:54:21.405 INFO 3776 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2017-05-23 23:54:21.406 INFO 3776 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2017-05-23 23:54:21.407 INFO 3776 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]

但是当我打开浏览器并访问http://localhost:9999时(我通过在application.properties中设置server.port=9999将端口更改为9999),结果发现连接被拒绝(也是通过curl)。所以我用命令lsof -i:9999检查端口也没有任何结果。

# liuxiaoyang @ SLs-Mac in ~ [0:08:14]
$ lsof -i:9999

# liuxiaoyang @ SLs-Mac in ~ [0:14:59] C:1
$ sudo lsof -i:9999
Password:

# liuxiaoyang @ SLs-Mac in ~ [0:15:02] C:1

但是一切似乎都很好,jps 命令显示项目 JVM 已经启动。 enter image description here我想知道为什么程序在一切看起来都正常的情况下无法监听配置的端口。

最佳答案

看来可能是网络环境的问题,去公司重新运行一下项目,就可以了。太神奇了。不知道spring boot内嵌Tomcat的细节。但我猜问题与网络接口(interface)绑定(bind)有关,因为我的计算机中有很多网络接口(interface)(有一些虚拟的)。

关于java - Spring Boot 无法监听端口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44139914/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com