Class TomcatServletWebServerFactory

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

ConfigurableServletWebServerFactory that can be used to create TomcatWebServers. Can be initialized using Spring's ServletContextInitializers or Tomcat LifecycleListeners.

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

Since:
4.0.0
Author:
Phillip Webb, Dave Syer, Brock Mills, Stephane Nicoll, Andy Wilkinson, EddĂș MelĂ©ndez, Christoffer Sawicki, Dawid Antecki, Moritz Halbritter, Scott Frederick
See Also:
  • Constructor Details

    • TomcatServletWebServerFactory

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

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

      public TomcatServletWebServerFactory(String contextPath, int port)
      Create a new TomcatServletWebServerFactory 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:
    • prepareContext

      protected void prepareContext(Host host, ServletContextInitializer[] initializers)
    • configureContext

      protected void configureContext(Context context, Iterable<ServletContextInitializer> initializers)
      Configure the Tomcat Context.
      Parameters:
      context - the Tomcat context
      initializers - initializers to apply
    • postProcessContext

      protected void postProcessContext(Context context)
      Post process the Tomcat Context before it's used with the Tomcat Server. Subclasses can override this method to apply additional processing to the Context.
      Parameters:
      context - the Tomcat Context
    • getTomcatWebServer

      protected TomcatWebServer getTomcatWebServer(Tomcat tomcat)
      Factory method called to create the TomcatWebServer. Subclasses can override this method to return a different TomcatWebServer or apply additional processing to the Tomcat server.
      Parameters:
      tomcat - the Tomcat server.
      Returns:
      a new TomcatWebServer instance
    • setResourceLoader

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

      public Set<String> getTldSkipPatterns()
      Returns a mutable set of the patterns that match jars to ignore for TLD scanning.
      Returns:
      the set of jars to ignore for TLD scanning
    • setTldSkipPatterns

      public void setTldSkipPatterns(Collection<String> patterns)
      Set the patterns that match jars to ignore for TLD scanning. See Tomcat's catalina.properties for typical values. Defaults to a list drawn from that source.
      Parameters:
      patterns - the jar patterns to skip when scanning for TLDs etc
    • addTldSkipPatterns

      public void addTldSkipPatterns(String... patterns)
      Add patterns that match jars to ignore for TLD scanning. See Tomcat's catalina.properties for typical values.
      Parameters:
      patterns - the additional jar patterns to skip when scanning for TLDs etc
    • getSettings

      public ServletWebServerSettings getSettings()
      Specified by:
      getSettings in interface ConfigurableServletWebServerFactory