Skip to content

Consider configuring a separate Service rather than a whole new embedded Tomcat when management.port != server.port #2855

@wilkinsona

Description

@wilkinsona

I think there may be some benefits in terms of memory usage and, perhaps, the ability to easily share access log configuration, thread pools, etc.

The configuration would look a bit like this:

    @Bean
    public TomcatEmbeddedServletContainerFactory tomcatFactory() {
        return new TomcatEmbeddedServletContainerFactory() {

            @Override
            protected TomcatEmbeddedServletContainer getTomcatEmbeddedServletContainer(
                    Tomcat tomcat) {
                Server server = tomcat.getServer();

                Service service = new StandardService();
                service.setName("other-port-service");
                Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
                connector.setPort(8081);
                service.addConnector(connector);
                server.addService(service);             

                Engine engine = new StandardEngine();
                service.setContainer(engine);

                Host host = new StandardHost();
                host.setName("other-port-host");
                engine.addChild(host);
                engine.setDefaultHost(host.getName());

                Context context = new StandardContext();
                context.addLifecycleListener(new FixContextListener());
                context.setName("other-port-context");
                context.setPath("");
                host.addChild(context);

                Wrapper wrapper = context.createWrapper();
                wrapper.setServlet(new MyServlet());
                wrapper.setName("other-port-servlet");
                context.addChild(wrapper);
                context.addServletMapping("/", wrapper.getName());

                return super.getTomcatEmbeddedServletContainer(tomcat);
            }
        };
    }

If there proves to be some benefit to this approach, we'd probably want to figure out how to do the same with Jetty and Undertow.

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: declinedA suggestion or change that we don't feel we should currently applytype: enhancementA general enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions