Class JettyServletWebServerFactory

All Implemented Interfaces:
Aware, ConfigurableJettyWebServerFactory, ConfigurableWebServerFactory, ErrorPageRegistry, WebServerFactory, ConfigurableServletWebServerFactory, ServletWebServerFactory, WebListenerRegistry, ResourceLoaderAware

public class JettyServletWebServerFactory extends AbstractServletWebServerFactory implements ConfigurableJettyWebServerFactory, ResourceLoaderAware
ServletWebServerFactory that can be used to create a JettyWebServer. Can be initialized using Spring's ServletContextInitializers or Jetty Configurations.

Unless explicitly configured otherwise this factory will create servers that listen for HTTP requests on port 8080.

Since:
2.0.0
Author:
Phillip Webb, Dave Syer, Andrey Hihlovskiy, Andy Wilkinson, EddĂș MelĂ©ndez, Venil Noronha, Henri Kerola
See Also:
  • Constructor Details

    • JettyServletWebServerFactory

      public JettyServletWebServerFactory()
      Create a new JettyServletWebServerFactory instance.
    • JettyServletWebServerFactory

      public JettyServletWebServerFactory(int port)
      Create a new JettyServletWebServerFactory that listens for requests using the specified port.
      Parameters:
      port - the port to listen on
    • JettyServletWebServerFactory

      public JettyServletWebServerFactory(String contextPath, int port)
      Create a new JettyServletWebServerFactory with the specified context path and port.
      Parameters:
      contextPath - the root context path
      port - the port to listen on
  • Method Details

    • getWebServer

      public WebServer getWebServer(ServletContextInitializer... initializers)
      Description copied from interface: ServletWebServerFactory
      Gets a new fully configured but paused WebServer instance. Clients should not be able to connect to the returned server until WebServer.start() is called (which happens when the ApplicationContext has been fully refreshed).
      Specified by:
      getWebServer in interface ServletWebServerFactory
      Parameters:
      initializers - ServletContextInitializers that should be applied as the server starts
      Returns:
      a fully configured and started WebServer
      See Also:
    • configureWebAppContext

      protected final void configureWebAppContext(org.eclipse.jetty.webapp.WebAppContext context, ServletContextInitializer... initializers)
      Configure the given Jetty WebAppContext for use.
      Parameters:
      context - the context to configure
      initializers - the set of initializers to apply
    • addDefaultServlet

      protected final void addDefaultServlet(org.eclipse.jetty.webapp.WebAppContext context)
      Add Jetty's DefaultServlet to the given WebAppContext.
      Parameters:
      context - the jetty WebAppContext
    • addJspServlet

      protected final void addJspServlet(org.eclipse.jetty.webapp.WebAppContext context)
      Add Jetty's JspServlet to the given WebAppContext.
      Parameters:
      context - the jetty WebAppContext
    • getWebAppContextConfigurations

      protected org.eclipse.jetty.webapp.Configuration[] getWebAppContextConfigurations(org.eclipse.jetty.webapp.WebAppContext webAppContext, ServletContextInitializer... initializers)
      Return the Jetty Configurations that should be applied to the server.
      Parameters:
      webAppContext - the Jetty WebAppContext
      initializers - the ServletContextInitializers to apply
      Returns:
      configurations to apply
    • getServletContextInitializerConfiguration

      protected org.eclipse.jetty.webapp.Configuration getServletContextInitializerConfiguration(org.eclipse.jetty.webapp.WebAppContext webAppContext, ServletContextInitializer... initializers)
      Return a Jetty Configuration that will invoke the specified ServletContextInitializers. By default this method will return a ServletContextInitializerConfiguration.
      Parameters:
      webAppContext - the Jetty WebAppContext
      initializers - the ServletContextInitializers to apply
      Returns:
      the Configuration instance
    • postProcessWebAppContext

      protected void postProcessWebAppContext(org.eclipse.jetty.webapp.WebAppContext webAppContext)
      Post process the Jetty WebAppContext before it's used with the Jetty Server. Subclasses can override this method to apply additional processing to the WebAppContext.
      Parameters:
      webAppContext - the Jetty WebAppContext
    • getJettyWebServer

      protected JettyWebServer getJettyWebServer(org.eclipse.jetty.server.Server server)
      Factory method called to create the JettyWebServer. Subclasses can override this method to return a different JettyWebServer or apply additional processing to the Jetty server.
      Parameters:
      server - the Jetty server.
      Returns:
      a new JettyWebServer instance
    • setResourceLoader

      public void setResourceLoader(ResourceLoader resourceLoader)
      Specified by:
      setResourceLoader in interface ResourceLoaderAware
    • setUseForwardHeaders

      public void setUseForwardHeaders(boolean useForwardHeaders)
      Description copied from interface: ConfigurableJettyWebServerFactory
      Set if x-forward-* headers should be processed.
      Specified by:
      setUseForwardHeaders in interface ConfigurableJettyWebServerFactory
      Parameters:
      useForwardHeaders - if x-forward headers should be used
    • setAcceptors

      public void setAcceptors(int acceptors)
      Description copied from interface: ConfigurableJettyWebServerFactory
      Set the number of acceptor threads to use.
      Specified by:
      setAcceptors in interface ConfigurableJettyWebServerFactory
      Parameters:
      acceptors - the number of acceptor threads to use
    • setSelectors

      public void setSelectors(int selectors)
      Description copied from interface: ConfigurableJettyWebServerFactory
      Set the number of selector threads to use.
      Specified by:
      setSelectors in interface ConfigurableJettyWebServerFactory
      Parameters:
      selectors - the number of selector threads to use
    • setServerCustomizers

      public void setServerCustomizers(Collection<? extends JettyServerCustomizer> customizers)
      Sets JettyServerCustomizers that will be applied to the Server before it is started. Calling this method will replace any existing customizers.
      Parameters:
      customizers - the Jetty customizers to apply
    • getServerCustomizers

      public Collection<JettyServerCustomizer> getServerCustomizers()
      Returns a mutable collection of Jetty JettyServerCustomizers that will be applied to the Server before it is created.
      Returns:
      the JettyServerCustomizers
    • addServerCustomizers

      public void addServerCustomizers(JettyServerCustomizer... customizers)
      Description copied from interface: ConfigurableJettyWebServerFactory
      Add JettyServerCustomizers that will be applied to the Server before it is started.
      Specified by:
      addServerCustomizers in interface ConfigurableJettyWebServerFactory
      Parameters:
      customizers - the customizers to add
    • setConfigurations

      public void setConfigurations(Collection<? extends org.eclipse.jetty.webapp.Configuration> configurations)
      Sets Jetty Configurations that will be applied to the WebAppContext before the server is created. Calling this method will replace any existing configurations.
      Parameters:
      configurations - the Jetty configurations to apply
    • getConfigurations

      public Collection<org.eclipse.jetty.webapp.Configuration> getConfigurations()
      Returns a mutable collection of Jetty Configurations that will be applied to the WebAppContext before the server is created.
      Returns:
      the Jetty Configurations
    • addConfigurations

      public void addConfigurations(org.eclipse.jetty.webapp.Configuration... configurations)
      Add Configurations that will be applied to the WebAppContext before the server is started.
      Parameters:
      configurations - the configurations to add
    • getThreadPool

      public org.eclipse.jetty.util.thread.ThreadPool getThreadPool()
      Returns a Jetty ThreadPool that should be used by the Server.
      Returns:
      a Jetty ThreadPool or null
    • setThreadPool

      public void setThreadPool(org.eclipse.jetty.util.thread.ThreadPool threadPool)
      Description copied from interface: ConfigurableJettyWebServerFactory
      Set the ThreadPool that should be used by the Server. If set to null (default), the Server creates a ThreadPool implicitly.
      Specified by:
      setThreadPool in interface ConfigurableJettyWebServerFactory
      Parameters:
      threadPool - the ThreadPool to be used