Skip to content

Instantly share code, notes, and snippets.

@lotabout
Created August 26, 2019 06:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lotabout/fb02706c9cb210426c259d2475fb5a70 to your computer and use it in GitHub Desktop.
Save lotabout/fb02706c9cb210426c259d2475fb5a70 to your computer and use it in GitHub Desktop.
How to add an additional connector in spring boot's application?
import org.apache.catalina.connector.Connector;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
import org.springframework.context.annotation.Bean;
@SpringBootApplication
public class SpringApplication {
public static void main(String[] args) {
new SpringApplicationBuilder(SpringApplication.class).run();
}
@Bean
public ServletWebServerFactory servletContainer() {
TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
connector.setPort(8081);
tomcat.addAdditionalTomcatConnectors(connector);
return tomcat;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment