You can change the HTTP endpoint and virtual host for the Spring Boot Actuator so that it
uses an endpoint and a virtual host other than the defaults for Liberty. You can change more server
settings for the actuator.
For the most current
information about deploying Spring Boot applications to Liberty, see the Open Liberty website website.
Before you begin
Install an existing Spring Boot 1.5 application WAR or JAR file,
helloSpringBootApp.jar, that includes the
spring-boot-starter-actuator
starter actuator and the default values that are used
for the server and management application properties. You also need an existing
helloserver
server configuration with the enabled Liberty features that are necessary to support
the Spring Boot application. Some of the Spring Boot application properties for configuring server
settings that are changed between Spring Boot 1.5 and Spring Boot 2.0. The example uses Spring Boot
1.5 application properties.
About this task
In the example, the helloSpringBootApp.jar
Spring Boot application that is
deployed to Liberty is configured so that it
does not use the Liberty default HTTP
endpoint or default virtual host. From the application HTTP port, configure the application to use a
different HTTP port for the actuator. Then, use the server.xml file to override
the server settings for the actuator.
Procedure
-
Use an existing
helloserver
server that includes the
hellospringboot.jar
application that is configured with the
springBootApplication
element in the server.xml file.
<springBootApplication location="hellospringboot.jar"/>
-
Override the default HTTP endpoint and default virtual host.
- Configure the
springBootApplication
element.
Add a command line argument for the application by using the applicationArgument
element. Pass the --server.liberty.use-default-host=false
argument.
<springBootApplication location="hellospringboot.jar">
<applicationArgument>--server.liberty.use-default-host=false</applicationArgument>
</springBootApplication>
- Start the server in the foreground by using the server run
helloserver command.
- Test the application at the
http://localhost:8080
URL.
- Test the actuator health endpoint at the
http://localhost:8080/health
URL.
-
To add a command line argument for the application, pass the
--management.port=9999
argument.
<springBootApplicationlocation="hellospringboot.jar">
<applicationArgument>--server.liberty.use-default-host=false</applicationArgument>
<applicationArgument>--management.port=9999</applicationArgument>
</springBootApplication>
- Test the application at the
http://localhost:8080
URL.
- Test the actuator health endpoint at the
http://localhost:9999/health
URL.
- Stop the server with the server stop helloserver
command.
-
For the actuator to use the HTTP port 9080 endpoint by default, configure the virtual host with
the
springBootVirtualHost-9999
argument.
<virtualHost id="springBootVirtualHost-9999">
<hostAlias>*:9080</hostAlias>
</virtualHost>
- Start the server in the foreground with the server run helloserver
command.
- Test the application at the
http://localhost:8080
URL.
- Test the actuator health endpoint at the
http://localhost:9080/health
URL.
- Stop the server with the server stop helloserver
command.
- Remove the
<virtualHost>
configuration from the
server.xml file.
-
Configure the HTTP endpoint for the actuator with the
9999
port and enable
access logging.
<httpEndpoint id="springBootHttpEndpoint-9999"httpPort="9999"httpsPort="-1">
<accessLogging/>
</httpEndpoint>
- Start the server in the foreground with the server run helloserver
command.
- Test the application at the
http://localhost:8080
URL.
- Test the actuator health endpoint at the
http://localhost:9999/health
URL.
- Check the /usr/servers/helloserver/logs/http_access.log file for
reports about accessing the
health
actuator.
- Stop the server with the server stop helloserver
command.
Tip: Use the
springBootVirtualHost-8080
and
springBootHttpEndpoint-8080
IDs to override the server settings for the main server
of the application. Similarly, you can override the SSL settings that the actuator endpoints use,
but overriding requires that the application includes configured Secure Sockets Layer (SSL) settings
for the actuator server. Assume that the actuator SSL settings are set with the following values and
that the application contains a
server-keystore.jks
keystore and a
server-truststore.jks
truststore on the class
path.
<featureManager>
<feature>jsp-2.3</feature>
<feature>springBoot-1.5</feature>
<feature>transportSecurity-1.0</feature>
</featureManager>
<springBootApplication location="hellospringboot.jar">
<applicationArgument>--server.liberty.use-default-host=false</applicationArgument>
<applicationArgument>--management.port=9999</applicationArgument>
<applicationArgument>--management.ssl.key-store=classpath:server-keystore.jks</applicationArgument>
<applicationArgument>--management.ssl.key-store-password=secret</applicationArgument>
<applicationArgument>--management.ssl.key-password=secret</applicationArgument>
<applicationArgument>--management.ssl.trust-store=classpath:server-truststore.jks</applicationArgument>
<applicationArgument>--management.ssl.trust-store-password=secret</applicationArgument>
</springBootApplication>
Enable
the transportSecurity-1.0
feature to support SSL for HTTPS endpoints. This setup
enables a keystore and a truststore to configure the HTTPS endpoint for the actuator. Access these
settings directly in the application.properties resource of the Spring Boot
application.
- Optional:
Override the SSL settings by specifying the
springBootSsl-9999
ID.
-
If the
httpEndpoint
element exists, remove it from the
server.xml file with the springBootHttpEndpoint-9999
ID.
-
Override the SSL settings that the actuator uses.
<ssl keyStoreRef="mykeystore" trustStoreRef="mytruststore" id="springBootSsl-9999"/>
<keyStore location="override-keystore.jks" password="secret" id="mykeystore"/>
<keyStore location="override-truststore.jks" password="secret" id="mytruststore"/>
-
Start the server in the foreground with the server run helloserver
command.
-
Test the application at the
http://localhost:8080
URL.
-
Test the actuator health endpoint at the secure
http://localhost:9999/health
URL.
-
Stop the server with the server stop helloserver command.
If the application was configured to use SSL, you can use the springBootSsl-9999
ID in the previous steps to override the SSL settings for the main server of the application.
- Optional:
Override the individual keystore or truststore by specifying the
springBootKeyStore-9999
or springBootTrustStore-9999
IDs.
-
If the
httpEndpoint
element exists, remove it from the
server.xml file with the springBootHttpEndpoint-9999
ID.
-
If the
ssl
and keyStore
elements exist, remove them from the
server.xml file with the springBootSsl-9999
ID.
-
Add one or both lines of code to override the keystore or truststore that the actuator
uses.
<keyStore location="override-keystore.jks" password="secret" id="springBootKeyStore-9999"/>
<keyStore location="override-truststore.jks" password="secret" id="springBootTrustStore-9999"/>
-
Start the server in the foreground with the server run helloserver
command.
-
Test the application at the
http://localhost:8080
URL.
-
Test the actuator health endpoint at the secure
https://localhost:9999/health
URL.
-
Stop the server with the server stop helloserver command.
If the server was configured to use SSL, you can use the springBootKeyStore-8080
and springBootTrustStore-8080
IDs in the previous steps to override the SSL
settings for the main server of the application.