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:

  1. How to change Tomcat port in Spring Boot application?
  2. Spring Boot- Embedded Tomcat failed to start.
  3. 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.
  4. 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.

/src/main/resources/application.properties
server.port=8085

2. Update via application.yml

Open the application.yml file of your Spring Boot project and add the following code.

/src/main/resources/application.yml
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.

CustomContainer.java
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 by WebServerFactoryCustomizer, and the ConfigurableEmbeddedServletContainer class is replaced with ConfigurableServletWebServerFactory.

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

  1. Server Tomcat Server at localhost failed to start in Eclipse
  2. Properties and Configuration
  3. Externalized Configuration
  4. Interface WebServerFactoryCustomizer<T extends WebServerFactory>
  5. Interface ConfigurableServletWebServerFactory

Similar Posts

About the Author

Atul Rai
I love sharing my experiments and ideas with everyone by writing articles on the latest technological trends. Read all published posts by Atul Rai.