0
votes

This happens when application is launched via run as spring boot through STS.

Spring boot: 1.4.0.M1

I have an IIS running on port 80 but however I have changed the sever.port through STS configuration properties to 8090. STS Screen shot

Why STS embedded tomcat is using the port 80 even after it is changed? Kind of puzzled.

2016-04-15 05:22:03,985 [main] ERROR o.s.boot.SpringApplication - Application startup failed org.springframework.boot.context.embedded.PortInUseException: Port 80 is already in use at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.checkThatConnectorsHaveStarted(TomcatEmbeddedServletContainer.java:187) at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.start(TomcatEmbeddedServletContainer.java:170) at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.startEmbeddedServletContainer(EmbeddedWebApplicationContext.java:293) at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:141) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:540) at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:768) at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:362) at org.springframework.boot.SpringApplication.run(SpringApplication.java:308) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1183) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1172) at com.jbhunt.web.FinanceClaimsApplication.main(FinanceClaimsApplication.java:71)

I do not find an option to change the port other than the above mentioned. Any help would be greatly appreciated.

1
Do you maybe have a conflicting setting in the .properties or .yaml file? E.g. management.port using actuator? - daniel.eichten
I have no property defined in .properties or in .yaml file. I tried mentioning the management.port to 8091 in STS property dialog but still no luck. - Masi
Did you passed any arguments in the second tab? - daniel.eichten
Boot's default port for HTTP is 8080, so you must have something setting it to 80 - Andy Wilkinson
Nope, nowhere it is set to 80. I even set it to 8090. Have not passed anything in second tab. - Masi

1 Answers

1
votes

You can configure your test class that load a context with a random port (working-with-random-ports).

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

WebEnvironment can bo set with the constants: RANDOM_PORT, DEFINED_PORT, MOCK or NONE.

The webEnvironment attribute allows specific “web environments” to be configured for the test. You can start tests with a MOCK servlet environment or with a real HTTP server running on either a RANDOM_PORT or a DEFINED_PORT.