2017-05-23 38 views
0

我使用MacOS的Sierra.And我用Springboot-CLI来产生一个空白的项目,并添加一个基本RESTController:SpringBoot不能听端口

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

我运行project.Everything与似乎很大在控制台输出:

. ____   _   __ _ _ 
/\\/___'_ __ _ _(_)_ __ __ _ \ \ \ \ 
(()\___ | '_ | '_| | '_ \/ _` | \ \ \ \ 
\\/ ___)| |_)| | | | | || (_| | )))) 
    ' |____| .__|_| |_|_| |_\__, |//// 
=========|_|==============|___/=/_/_/_/ 
:: 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[email protected]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(我用一套server.port在application.properties = 9999更改端口9999),事实证明,拒绝连接(也可通过卷曲)。因此,我用命令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 我想知道在一切看起来正确的时候,程序不能听到配置的端口的原因。

+0

当应用程序启动时,它会列出它正在监听的所有端口。该名单是9999?向我们展示启动输出。 – csmckelvey

+0

尝试推出'server.port = 8090' – Reborn

+0

我试过了。我也以为是端口问题。不过当我改了端口。没有改变。@ Reborn – CALTyang

回答

0

看来网络环境可能会导致这个问题。当我去公司并重新运行这个项目时,它工作正常。惊呆了。我不知道Spring Boot嵌入式Tomcat的细节。但我想这个问题与网络接口绑定有关,因为我的电脑中有很多网络接口(有些是虚拟接口)。