Jetty.xml file
The Jetty microservice comes with a bare-bones jetty.xml file which can be modified to suite any needs.
The jetty.xml can be located in either the . or files working directory or classpath.
It can also be specified in any of the following ways:
- Supplying a
@Bean JettySettingswhosejettyXml(Object, boolean resolveVars)builder method sets the raw XML contents (and optionally requests SVL var-resolution).
@Configuration
public class MyJettyConfig {
@Bean
JettySettings jettySettings() {
return JettySettings.create()
.jettyXml(myXmlReader, true)
.build();
}
}
- Specifying the location using a
Jetty-Configvalue in theMANIFEST.MFfile.
Jetty-Config: files/jetty.xml
- Specifying the location using the "Jetty/config" configuration value.
#=======================================================================================================================
# Jetty settings
#=======================================================================================================================
[Jetty]
# Path of the jetty.xml file used to configure the Jetty server.
config = files/jetty.xml
SVL variables in the jetty.xml file can be automatically resolved by the microservice when the
Jetty/resolveVars=true config flag is set (or via JettySettings.jettyXml(..., true)).
This allows you to reference values in your configuration file from the jetty.xml file.
The HTTP port used is controlled via the following:
- Supplying a
@Bean JettySettingswhoseports(int...)builder method specifies a list of candidate ports.
@Configuration
public class MyJettyConfig {
@Bean
JettySettings jettySettings() {
return JettySettings.create()
.ports(1000, 2000, 0, 0, 0) // Try port 1000, then 2000, then 3 random ports.
.build();
}
}
- The "Jetty/port" configuration property.
#=======================================================================================================================
# Jetty settings
#=======================================================================================================================
[Jetty]
# Port to use for the jetty server.
# You can specify multiple ports. The first available will be used. '0' indicates to try a random port.
port = 1000,2000,0,0,0
The first available port is then made available through the system property "availablePort" so that it can be referenced
in your jetty.xml file.
<Set name="connectors">
<Array type="org.eclipse.jetty.server.Connector">
<Item>
<New class="org.eclipse.jetty.server.ServerConnector">
<Arg>
<Ref refid="ExampleServer" />
</Arg>
<Set name="port">$S{availablePort,8080}</Set>
</New>
</Item>
</Array>
</Set>
A @Bean JettyServerFactory can also be supplied (or contributed by JettyConfiguration as its default)
to fully control how the Server is built from the resolved XML.