我正在使用MacOS Sierra.And我使用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),结果证明连接被拒绝(也是通过卷曲)。所以我使用命令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已经启动。 我想知道在一切看起来正确的情况下程序无法收听配置的端口的原因。
答案 0 :(得分:0)
似乎网络环境可能会导致问题。当我去公司并重新运行项目时,它的工作原理。惊人的。我不知道嵌入式Tomcat的spring boot的细节。但我想这个问题与网络接口绑定有关,因为我的计算机中有很多网络接口(有一些虚拟接口)。