Spring Boot- The Tomcat connector configured to listen on port 8080 failed to start
While developing a Spring Boot application, you might be faced with the problem that embedded Tomcat Server failed to start and the error message is “The Tomcat connector configured to listen on port 8080 failed to start. The port may already be in use or the connector may be misconfigured”. This problem comes when you try to execute multiple projects in your IDE at the same port i.e. 8080. By default embedded Tomcat server runs on 8080 port in STS.
This article helps to solve these following question also:
- How to change Tomcat port in Spring Boot application?
- Spring Boot- Embedded Tomcat failed to start.
- The Tomcat connector configured to listen on port 8080 failed to start. The port may already be in use or the connector may be misconfigured.
- Spring Boot application failed to start.
P.S- Tested with Spring Boot 2.0.7.RELEASE
1. Update via application.properties
Open the application.properties file of your Spring Boot project and add the following code.
server.port=8085
2. Update via application.yml
Open the application.yml file of your Spring Boot project and add the following code.
server:
port: 8085
3. Update via WebServerFactoryCustomizer
Create a CustomContainer
class, implements the WebServerFactoryCustomizer
interface, overrides its customize
method and set your new port. This will overrides application.properties and application.yml settings.
package org.websparrow;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
import org.springframework.stereotype.Component;
@Component
public class CustomContainer implements WebServerFactoryCustomizer<ConfigurableServletWebServerFactory> {
@Override
public void customize(ConfigurableServletWebServerFactory factory) {
factory.setPort(8085);
}
}
Note: In Spring Boot 2, the
EmbeddedServletContainerCustomizer
interface is replaced byWebServerFactoryCustomizer
, and theConfigurableEmbeddedServletContainer
class is replaced withConfigurableServletWebServerFactory
.
If you are using Spring Boot 1.x.x.RELEASE version, your code will be:
package org.websparrow;
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.stereotype.Component;
@Component
public class CustomContainer implements EmbeddedServletContainerCustomizer {
@Override
public void customize(ConfigurableEmbeddedServletContainer container) {
container.setPort(8085);
}
}
References
- Server Tomcat Server at localhost failed to start in Eclipse
- Properties and Configuration
- Externalized Configuration
- Interface WebServerFactoryCustomizer<T extends WebServerFactory>
- Interface ConfigurableServletWebServerFactory