org.springframework.boot.context.embedded.tomcat
Class TomcatEmbeddedServletContainerFactory

java.lang.Object
  extended by org.springframework.boot.context.embedded.AbstractEmbeddedServletContainerFactory
      extended by org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory
All Implemented Interfaces:
org.springframework.beans.factory.Aware, ConfigurableEmbeddedServletContainerFactory, EmbeddedServletContainerFactory, org.springframework.context.ResourceLoaderAware

public class TomcatEmbeddedServletContainerFactory
extends AbstractEmbeddedServletContainerFactory
implements org.springframework.context.ResourceLoaderAware

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

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

Author:
Phillip Webb, Dave Syer
See Also:
AbstractEmbeddedServletContainerFactory.setPort(int), setContextLifecycleListeners(Collection), TomcatEmbeddedServletContainer

Field Summary
 
Fields inherited from class org.springframework.boot.context.embedded.AbstractEmbeddedServletContainerFactory
logger
 
Constructor Summary
TomcatEmbeddedServletContainerFactory()
          Create a new TomcatEmbeddedServletContainerFactory instance.
TomcatEmbeddedServletContainerFactory(int port)
          Create a new TomcatEmbeddedServletContainerFactory that listens for requests using the specified port.
TomcatEmbeddedServletContainerFactory(String contextPath, int port)
          Create a new TomcatEmbeddedServletContainerFactory with the specified context path and port.
 
Method Summary
 void addContextCustomizers(TomcatContextCustomizer... tomcatContextCustomizers)
          Add TomcatContextCustomizers that should be added to the Tomcat Context.
 void addContextLifecycleListeners(org.apache.catalina.LifecycleListener... contextLifecycleListeners)
          Add LifecycleListeners that should be added to the Tomcat Context.
 void addContextValves(org.apache.catalina.Valve... contextValves)
          Add Valves that should be applied to the Tomcat Context.
protected  void configureContext(org.apache.catalina.Context context, ServletContextInitializer[] initializers)
          Configure the Tomcat Context.
protected  void customizeConnector(org.apache.catalina.connector.Connector connector)
           
 Collection<org.apache.catalina.LifecycleListener> getContextLifecycleListeners()
          Returns a mutable collection of the LifecycleListeners that will be applied to the Tomcat Context .
 EmbeddedServletContainer getEmbeddedServletContainer(ServletContextInitializer... initializers)
          Gets a new fully configured but paused EmbeddedServletContainer instance.
 Collection<TomcatContextCustomizer> getTomcatContextCustomizers()
          Returns a mutable collection of the TomcatContextCustomizers that will be applied to the Tomcat Context .
protected  TomcatEmbeddedServletContainer getTomcatEmbeddedServletContainer(org.apache.catalina.startup.Tomcat tomcat)
          Factory method called to create the TomcatEmbeddedServletContainer.
 Collection<org.apache.catalina.Valve> getValves()
          Returns a mutable collection of the Valves that will be applied to the Tomcat Context.
protected  void postProcessContext(org.apache.catalina.Context context)
          Post process the Tomcat Context before it used with the Tomcat Server.
protected  void prepareContext(org.apache.catalina.Host host, ServletContextInitializer[] initializers)
           
 void setBaseDirectory(File baseDirectory)
          Set the Tomcat base directory.
 void setContextLifecycleListeners(Collection<? extends org.apache.catalina.LifecycleListener> contextLifecycleListeners)
          Set LifecycleListeners that should be applied to the Tomcat Context .
 void setContextValves(Collection<? extends org.apache.catalina.Valve> contextValves)
          Set Valves that should be applied to the Tomcat Context.
 void setProtocol(String protocol)
          The Tomcat protocol to use when create the Connector.
 void setResourceLoader(org.springframework.core.io.ResourceLoader resourceLoader)
           
 void setTomcatContextCustomizers(Collection<? extends TomcatContextCustomizer> tomcatContextCustomizers)
          Set TomcatContextCustomizers that should be applied to the Tomcat Context .
 
Methods inherited from class org.springframework.boot.context.embedded.AbstractEmbeddedServletContainerFactory
addErrorPages, addInitializers, getAddress, getContextPath, getDocumentRoot, getErrorPages, getInitializers, getJspServletClassName, getMimeMappings, getPort, getSessionTimeout, getValidDocumentRoot, isRegisterDefaultServlet, isRegisterJspServlet, mergeInitializers, setAddress, setContextPath, setDocumentRoot, setErrorPages, setInitializers, setJspServletClassName, setMimeMappings, setPort, setRegisterDefaultServlet, setRegisterJspServlet, setSessionTimeout, setSessionTimeout
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TomcatEmbeddedServletContainerFactory

public TomcatEmbeddedServletContainerFactory()
Create a new TomcatEmbeddedServletContainerFactory instance.


TomcatEmbeddedServletContainerFactory

public TomcatEmbeddedServletContainerFactory(int port)
Create a new TomcatEmbeddedServletContainerFactory that listens for requests using the specified port.

Parameters:
port - the port to listen on

TomcatEmbeddedServletContainerFactory

public TomcatEmbeddedServletContainerFactory(String contextPath,
                                             int port)
Create a new TomcatEmbeddedServletContainerFactory with the specified context path and port.

Parameters:
contextPath - root the context path
port - the port to listen on
Method Detail

getEmbeddedServletContainer

public EmbeddedServletContainer getEmbeddedServletContainer(ServletContextInitializer... initializers)
Description copied from interface: EmbeddedServletContainerFactory
Gets a new fully configured but paused EmbeddedServletContainer instance. Clients should not be able to connect to the returned server until EmbeddedServletContainer.start() is called (which happens when the ApplicationContext has been fully refreshed).

Specified by:
getEmbeddedServletContainer in interface EmbeddedServletContainerFactory
Parameters:
initializers - ServletContextInitializers that should be applied as the container starts
Returns:
a fully configured and started EmbeddedServletContainer
See Also:
EmbeddedServletContainer.stop()

prepareContext

protected void prepareContext(org.apache.catalina.Host host,
                              ServletContextInitializer[] initializers)

customizeConnector

protected void customizeConnector(org.apache.catalina.connector.Connector connector)

configureContext

protected void configureContext(org.apache.catalina.Context context,
                                ServletContextInitializer[] initializers)
Configure the Tomcat Context.

Parameters:
context - the Tomcat context
initializers - initializers to apply

postProcessContext

protected void postProcessContext(org.apache.catalina.Context context)
Post process the Tomcat Context before it used with the Tomcat Server. Subclasses can override this method to apply additional processing to the Context.

Parameters:
context - the Tomcat Context

getTomcatEmbeddedServletContainer

protected TomcatEmbeddedServletContainer getTomcatEmbeddedServletContainer(org.apache.catalina.startup.Tomcat tomcat)
Factory method called to create the TomcatEmbeddedServletContainer. Subclasses can override this method to return a different TomcatEmbeddedServletContainer or apply additional processing to the Tomcat server.

Parameters:
tomcat - the Tomcat server.
Returns:
a new TomcatEmbeddedServletContainer instance

setResourceLoader

public void setResourceLoader(org.springframework.core.io.ResourceLoader resourceLoader)
Specified by:
setResourceLoader in interface org.springframework.context.ResourceLoaderAware

setBaseDirectory

public void setBaseDirectory(File baseDirectory)
Set the Tomcat base directory. If not specified a temporary directory will be used.

Parameters:
baseDirectory - the tomcat base directory

setProtocol

public void setProtocol(String protocol)
The Tomcat protocol to use when create the Connector.

See Also:
Connector.Connector(String)

setContextValves

public void setContextValves(Collection<? extends org.apache.catalina.Valve> contextValves)
Set Valves that should be applied to the Tomcat Context. Calling this method will replace any existing listeners.

Parameters:
contextValves - the valves to set

getValves

public Collection<org.apache.catalina.Valve> getValves()
Returns a mutable collection of the Valves that will be applied to the Tomcat Context.

Returns:
the contextValves the valves that will be applied

addContextValves

public void addContextValves(org.apache.catalina.Valve... contextValves)
Add Valves that should be applied to the Tomcat Context.

Parameters:
contextValves - the valves to add

setContextLifecycleListeners

public void setContextLifecycleListeners(Collection<? extends org.apache.catalina.LifecycleListener> contextLifecycleListeners)
Set LifecycleListeners that should be applied to the Tomcat Context . Calling this method will replace any existing listeners.

Parameters:
contextLifecycleListeners - the listeners to set

getContextLifecycleListeners

public Collection<org.apache.catalina.LifecycleListener> getContextLifecycleListeners()
Returns a mutable collection of the LifecycleListeners that will be applied to the Tomcat Context .

Returns:
the contextLifecycleListeners the listeners that will be applied

addContextLifecycleListeners

public void addContextLifecycleListeners(org.apache.catalina.LifecycleListener... contextLifecycleListeners)
Add LifecycleListeners that should be added to the Tomcat Context.

Parameters:
contextLifecycleListeners - the listeners to add

setTomcatContextCustomizers

public void setTomcatContextCustomizers(Collection<? extends TomcatContextCustomizer> tomcatContextCustomizers)
Set TomcatContextCustomizers that should be applied to the Tomcat Context . Calling this method will replace any existing customizers.

Parameters:
tomcatContextCustomizers - the customizers to set

getTomcatContextCustomizers

public Collection<TomcatContextCustomizer> getTomcatContextCustomizers()
Returns a mutable collection of the TomcatContextCustomizers that will be applied to the Tomcat Context .

Returns:
the tomcatContextCustomizers the listeners that will be applied

addContextCustomizers

public void addContextCustomizers(TomcatContextCustomizer... tomcatContextCustomizers)
Add TomcatContextCustomizers that should be added to the Tomcat Context.

Parameters:
tomcatContextCustomizers - the customizers to add


Copyright © 2013. All Rights Reserved.