Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Spring Boot (auto-)configuration class that defines an additional Tomcat Connector for health checks
import org.apache.catalina.connector.Connector;
import org.apache.coyote.AbstractProtocol;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
public class TomcatAutoConfiguration {
* Creates an addition {@link Connector} for Tomcat that we use for the health checks.
* This ensures that even when all the request handling threads from the regular connector
* are in use, we can still respond to health check requests made on port 8888.
WebServerFactoryCustomizer<TomcatServletWebServerFactory> tomcatHealthConnectorCustomizer(TomcatAutoConfiguration.HealthConnectorProperties connector) {
return server -> {
Connector healthConnector = new Connector();
AbstractProtocol protocol = (AbstractProtocol) healthConnector.getProtocolHandler();
public static class HealthConnectorProperties {
/** port number used by the addition Tomcat connector for health checks */
private int port = 8888;
private int minThreads = 1;
private int maxThreads = 5;
public int getPort() {
return port;
public void setPort(int port) {
this.port = port;
public int getMinThreads() {
return minThreads;
public void setMinThreads(int minThreads) {
this.minThreads = minThreads;
public int getMaxThreads() {
return maxThreads;
public void setMaxThreads(int maxThreads) {
this.maxThreads = maxThreads;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment