2016-04-15 109 views
0

当通过运行启动应用程序(通过STS进行弹簧启动)时会发生这种情况。org.springframework.boot.context.embedded.PortInUseException:端口80已在使用中

春季启动: 1.4.0.M1

我对端口80上运行的IIS,但不过我已经通过STS配置属性改变了sever.port到。 STS Screen shot

为什么STS嵌入式tomcat即使在更改后也使用端口80?那种困惑。

2016年4月15日05:22:03985 [主]错误osboot.SpringApplication - 应用程序启动失败 org.springframework.boot.context.embedded.PortInUseException:端口 80已在使用在 org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.checkThatConnectorsHaveStarted(TomcatEmbeddedServletContainer.java:187) 在 org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.start(TomcatEmbeddedServletContainer.java:170) at org.springframework.boot.context。 embedded.EmbeddedWebApplicationContext.startEmbeddedServletContainer(EmbeddedWebApplicationContext.java:293) 在 org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:141) 在 org.springframework.context.support.AbstractApplicationContext.refresh( AbstractApplicationContext.java:540) 在 org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) 在 org.springframework.boot.SpringApplication.refresh(SpringApplication.java:768) 在 org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:362) 在 org.springframework.boot.SpringApplication.run(SpringApplication.java:308) 在 org.springframework.boot.SpringApplication.run(SpringApplication.java:1183) 在 org.springframework.boot.SpringApplication.run (SpringApplication.java:1172) 在 com.jbhunt.web.FinanceClaimsApplication.main(FinanceClaimsApplication.java:71)

我没有找到一个选项来改变比上述提到的 其他端口。任何帮助将不胜感激。

+0

你可能在'.properties'或'.yaml'文件中有冲突的设置吗?例如。使用执行器的'management.port'? –

+0

我没有在'.properties'或'.yaml'文件中定义的属性。我尝试在STS属性对话框中提到8091的'management.port',但仍然没有运气。 – Masi

+0

你在第二个标签中传递了任何参数吗? –

回答

0

您可以配置使用随机端口加载上下文的测试类(working-with-random-ports)。

@RunWith(SpringRunner.class) 
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) 

WebEnvironment可以设置常量:RANDOM_PORT,DEFINED_PORT,MOCK或NONE。

webEnvironment属性允许为测试配置特定的“Web环境”。您可以使用MOCK servlet环境或运行在RANDOM_PORT或DEFINED_PORT上的真实HTTP服务器开始测试。