Configuring the HTTP endpoint and virtual host for the Spring Boot Actuator

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.

Open Liberty 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

  1. 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"/>
  2. Override the default HTTP endpoint and default virtual host.
    1. 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>
    2. Start the server in the foreground by using the server run helloserver command.
    3. Test the application at the http://localhost:8080 URL.
    4. Test the actuator health endpoint at the http://localhost:8080/health URL.
  3. 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>
    1. Test the application at the http://localhost:8080 URL.
    2. Test the actuator health endpoint at the http://localhost:9999/health URL.
    3. Stop the server with the server stop helloserver command.
  4. 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>
    1. Start the server in the foreground with the server run helloserver command.
    2. Test the application at the http://localhost:8080 URL.
    3. Test the actuator health endpoint at the http://localhost:9080/health URL.
    4. Stop the server with the server stop helloserver command.
    5. Remove the <virtualHost> configuration from the server.xml file.
  5. 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>
    1. Start the server in the foreground with the server run helloserver command.
    2. Test the application at the http://localhost:8080 URL.
    3. Test the actuator health endpoint at the http://localhost:9999/health URL.
    4. Check the /usr/servers/helloserver/logs/http_access.log file for reports about accessing the health actuator.
    5. 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.

  6. Optional: Override the SSL settings by specifying the springBootSsl-9999 ID.
    1. If the httpEndpoint element exists, remove it from the server.xml file with the springBootHttpEndpoint-9999 ID.
    2. 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"/>
    3. Start the server in the foreground with the server run helloserver command.
    4. Test the application at the http://localhost:8080 URL.
    5. Test the actuator health endpoint at the secure http://localhost:9999/health URL.
    6. 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.

  7. Optional: Override the individual keystore or truststore by specifying the springBootKeyStore-9999 or springBootTrustStore-9999 IDs.
    1. If the httpEndpoint element exists, remove it from the server.xml file with the springBootHttpEndpoint-9999 ID.
    2. If the ssl and keyStore elements exist, remove them from the server.xml file with the springBootSsl-9999 ID.
    3. 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"/>
    4. Start the server in the foreground with the server run helloserver command.
    5. Test the application at the http://localhost:8080 URL.
    6. Test the actuator health endpoint at the secure https://localhost:9999/health URL.
    7. 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.