首页 文章

org.springframework.boot.context.embedded.PortInUseException:端口80已被使用

提问于
浏览
0

当通过STS弹出启动运行应用程序时会发生这种情况 .

Spring boot: 1.4.0.M1

我在端口80上运行了IIS,但是我已经通过STS配置属性将sever.port更改为 8090 . STS Screen shot

为什么STS嵌入式tomcat即使在更改后仍在使用端口80?有点疑惑 .

2016-04-15 05:22:03,985 [main]错误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.EmbeddedWebApplicationContext的org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.start(TomcatEmbeddedServletContainer.java:170) . startEmbeddedServletContainer(EmbeddedWebApplicationContext.java:293)org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:141)org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:540)at org org.springframework.b上的.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) oot.SpringApplication.refresh(SpringApplication.java:768)位于org.springframework的org.springframework.boot.SpringApplication.run(SpringApplication.java:308)org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:362) .boot.SpringApplication.run(SpringApplication.java:1183)位于org.springframework.boot.SpringApplication.run(SpringApplication.java:1172)的com.jbhunt.web.FinanceClaimsApplication.main(FinanceClaimsApplication.java:71)

除了上面提到的,我没有找到更改端口的选项 . 任何帮助将不胜感激 .

1 回答

  • 0

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

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

    Web环境可以使用常量设置:RANDOM_PORT,DEFINED_PORT,MOCK或NONE .

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

相关问题