Class JettyServletWebServerFactory
java.lang.Object
org.springframework.boot.web.server.AbstractConfigurableWebServerFactory
org.springframework.boot.web.servlet.server.AbstractServletWebServerFactory
org.springframework.boot.web.embedded.jetty.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 ServletContextInitializer
s or Jetty
Configuration
s.
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:
-
Field Summary
Fields inherited from class org.springframework.boot.web.servlet.server.AbstractServletWebServerFactory
logger
-
Constructor Summary
ConstructorsConstructorDescriptionCreate a newJettyServletWebServerFactory
instance.JettyServletWebServerFactory
(int port) Create a newJettyServletWebServerFactory
that listens for requests using the specified port.JettyServletWebServerFactory
(String contextPath, int port) Create a newJettyServletWebServerFactory
with the specified context path and port. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addConfigurations
(org.eclipse.jetty.webapp.Configuration... configurations) AddConfiguration
s that will be applied to theWebAppContext
before the server is started.protected final void
addDefaultServlet
(org.eclipse.jetty.webapp.WebAppContext context) Add Jetty'sDefaultServlet
to the givenWebAppContext
.protected final void
addJspServlet
(org.eclipse.jetty.webapp.WebAppContext context) Add Jetty'sJspServlet
to the givenWebAppContext
.void
addServerCustomizers
(JettyServerCustomizer... customizers) AddJettyServerCustomizer
s that will be applied to theServer
before it is started.protected final void
configureWebAppContext
(org.eclipse.jetty.webapp.WebAppContext context, ServletContextInitializer... initializers) Configure the given JettyWebAppContext
for use.Collection<org.eclipse.jetty.webapp.Configuration>
Returns a mutable collection of JettyConfiguration
s that will be applied to theWebAppContext
before the server is created.protected JettyWebServer
getJettyWebServer
(org.eclipse.jetty.server.Server server) Factory method called to create theJettyWebServer
.Returns a mutable collection of JettyJettyServerCustomizer
s that will be applied to theServer
before the it is created.protected org.eclipse.jetty.webapp.Configuration
getServletContextInitializerConfiguration
(org.eclipse.jetty.webapp.WebAppContext webAppContext, ServletContextInitializer... initializers) Return a JettyConfiguration
that will invoke the specifiedServletContextInitializer
s.org.eclipse.jetty.util.thread.ThreadPool
Returns a JettyThreadPool
that should be used by theServer
.protected org.eclipse.jetty.webapp.Configuration[]
getWebAppContextConfigurations
(org.eclipse.jetty.webapp.WebAppContext webAppContext, ServletContextInitializer... initializers) Return the JettyConfiguration
s that should be applied to the server.getWebServer
(ServletContextInitializer... initializers) Gets a new fully configured but pausedWebServer
instance.protected void
postProcessWebAppContext
(org.eclipse.jetty.webapp.WebAppContext webAppContext) Post process the JettyWebAppContext
before it's used with the Jetty Server.void
setAcceptors
(int acceptors) Set the number of acceptor threads to use.void
setConfigurations
(Collection<? extends org.eclipse.jetty.webapp.Configuration> configurations) Sets JettyConfiguration
s that will be applied to theWebAppContext
before the server is created.void
setResourceLoader
(ResourceLoader resourceLoader) void
setSelectors
(int selectors) Set the number of selector threads to use.void
setServerCustomizers
(Collection<? extends JettyServerCustomizer> customizers) SetsJettyServerCustomizer
s that will be applied to theServer
before it is started.void
setThreadPool
(org.eclipse.jetty.util.thread.ThreadPool threadPool) Set theThreadPool
that should be used by theServer
.void
setUseForwardHeaders
(boolean useForwardHeaders) Set if x-forward-* headers should be processed.Methods inherited from class org.springframework.boot.web.servlet.server.AbstractServletWebServerFactory
addCookieSameSiteSuppliers, addInitializers, addWebListeners, getContextPath, getCookieSameSiteSuppliers, getDisplayName, getDocumentRoot, getInitParameters, getJsp, getLocaleCharsetMappings, getMimeMappings, getSession, getUrlsOfJarsWithMetaInfResources, getValidDocumentRoot, getValidSessionStoreDir, getValidSessionStoreDir, getWebListenerClassNames, isRegisterDefaultServlet, mergeInitializers, setContextPath, setCookieSameSiteSuppliers, setDisplayName, setDocumentRoot, setInitializers, setInitParameters, setJsp, setLocaleCharsetMappings, setMimeMappings, setRegisterDefaultServlet, setSession, shouldRegisterJspServlet
Methods inherited from class org.springframework.boot.web.server.AbstractConfigurableWebServerFactory
addErrorPages, createTempDir, getAddress, getCompression, getErrorPages, getHttp2, getPort, getServerHeader, getShutdown, getSsl, getSslStoreProvider, setAddress, setCompression, setErrorPages, setHttp2, setPort, setServerHeader, setShutdown, setSsl, setSslStoreProvider
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.boot.web.server.ConfigurableWebServerFactory
setAddress, setCompression, setErrorPages, setHttp2, setPort, setServerHeader, setShutdown, setSsl, setSslStoreProvider
Methods inherited from interface org.springframework.boot.web.server.ErrorPageRegistry
addErrorPages
-
Constructor Details
-
JettyServletWebServerFactory
public JettyServletWebServerFactory()Create a newJettyServletWebServerFactory
instance. -
JettyServletWebServerFactory
public JettyServletWebServerFactory(int port) Create a newJettyServletWebServerFactory
that listens for requests using the specified port.- Parameters:
port
- the port to listen on
-
JettyServletWebServerFactory
Create a newJettyServletWebServerFactory
with the specified context path and port.- Parameters:
contextPath
- the root context pathport
- the port to listen on
-
-
Method Details
-
getWebServer
Description copied from interface:ServletWebServerFactory
Gets a new fully configured but pausedWebServer
instance. Clients should not be able to connect to the returned server untilWebServer.start()
is called (which happens when theApplicationContext
has been fully refreshed).- Specified by:
getWebServer
in interfaceServletWebServerFactory
- Parameters:
initializers
-ServletContextInitializer
s 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 JettyWebAppContext
for use.- Parameters:
context
- the context to configureinitializers
- the set of initializers to apply
-
addDefaultServlet
protected final void addDefaultServlet(org.eclipse.jetty.webapp.WebAppContext context) Add Jetty'sDefaultServlet
to the givenWebAppContext
.- Parameters:
context
- the jettyWebAppContext
-
addJspServlet
protected final void addJspServlet(org.eclipse.jetty.webapp.WebAppContext context) Add Jetty'sJspServlet
to the givenWebAppContext
.- Parameters:
context
- the jettyWebAppContext
-
getWebAppContextConfigurations
protected org.eclipse.jetty.webapp.Configuration[] getWebAppContextConfigurations(org.eclipse.jetty.webapp.WebAppContext webAppContext, ServletContextInitializer... initializers) Return the JettyConfiguration
s that should be applied to the server.- Parameters:
webAppContext
- the JettyWebAppContext
initializers
- theServletContextInitializer
s to apply- Returns:
- configurations to apply
-
getServletContextInitializerConfiguration
protected org.eclipse.jetty.webapp.Configuration getServletContextInitializerConfiguration(org.eclipse.jetty.webapp.WebAppContext webAppContext, ServletContextInitializer... initializers) Return a JettyConfiguration
that will invoke the specifiedServletContextInitializer
s. By default this method will return aServletContextInitializerConfiguration
.- Parameters:
webAppContext
- the JettyWebAppContext
initializers
- theServletContextInitializer
s to apply- Returns:
- the
Configuration
instance
-
postProcessWebAppContext
protected void postProcessWebAppContext(org.eclipse.jetty.webapp.WebAppContext webAppContext) Post process the JettyWebAppContext
before it's used with the Jetty Server. Subclasses can override this method to apply additional processing to theWebAppContext
.- Parameters:
webAppContext
- the JettyWebAppContext
-
getJettyWebServer
Factory method called to create theJettyWebServer
. Subclasses can override this method to return a differentJettyWebServer
or apply additional processing to the Jetty server.- Parameters:
server
- the Jetty server.- Returns:
- a new
JettyWebServer
instance
-
setResourceLoader
- Specified by:
setResourceLoader
in interfaceResourceLoaderAware
-
setUseForwardHeaders
public void setUseForwardHeaders(boolean useForwardHeaders) Description copied from interface:ConfigurableJettyWebServerFactory
Set if x-forward-* headers should be processed.- Specified by:
setUseForwardHeaders
in interfaceConfigurableJettyWebServerFactory
- 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 interfaceConfigurableJettyWebServerFactory
- 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 interfaceConfigurableJettyWebServerFactory
- Parameters:
selectors
- the number of selector threads to use
-
setServerCustomizers
SetsJettyServerCustomizer
s that will be applied to theServer
before it is started. Calling this method will replace any existing customizers.- Parameters:
customizers
- the Jetty customizers to apply
-
getServerCustomizers
Returns a mutable collection of JettyJettyServerCustomizer
s that will be applied to theServer
before the it is created.- Returns:
- the
JettyServerCustomizer
s
-
addServerCustomizers
Description copied from interface:ConfigurableJettyWebServerFactory
AddJettyServerCustomizer
s that will be applied to theServer
before it is started.- Specified by:
addServerCustomizers
in interfaceConfigurableJettyWebServerFactory
- Parameters:
customizers
- the customizers to add
-
setConfigurations
public void setConfigurations(Collection<? extends org.eclipse.jetty.webapp.Configuration> configurations) Sets JettyConfiguration
s that will be applied to theWebAppContext
before the server is created. Calling this method will replace any existing configurations.- Parameters:
configurations
- the Jetty configurations to apply
-
getConfigurations
Returns a mutable collection of JettyConfiguration
s that will be applied to theWebAppContext
before the server is created.- Returns:
- the Jetty
Configuration
s
-
addConfigurations
public void addConfigurations(org.eclipse.jetty.webapp.Configuration... configurations) AddConfiguration
s that will be applied to theWebAppContext
before the server is started.- Parameters:
configurations
- the configurations to add
-
getThreadPool
public org.eclipse.jetty.util.thread.ThreadPool getThreadPool()Returns a JettyThreadPool
that should be used by theServer
.- Returns:
- a Jetty
ThreadPool
ornull
-
setThreadPool
public void setThreadPool(org.eclipse.jetty.util.thread.ThreadPool threadPool) Description copied from interface:ConfigurableJettyWebServerFactory
Set theThreadPool
that should be used by theServer
. If set tonull
(default), theServer
creates aThreadPool
implicitly.- Specified by:
setThreadPool
in interfaceConfigurableJettyWebServerFactory
- Parameters:
threadPool
- the ThreadPool to be used
-