Enable Spring Boot Actuator - Bloomreach Experience - Headless Digital Experience Platform

Enable Spring Boot Actuator

This feature is available since Bloomreach Experience Manager 14.6.0

Introduction

Goal

Enable Spring Boot Actuator in an implementation project's CMS application in order to access additional monitoring and management features.

Background

Since version 14.6, Spring Boot framework has been integrated into the CMS application, adding support for a number of additional features to help in monitoring and managing the CMS application when it is pushed to production. The CMS application can be managed and monitored through HTTP endpoints or JMX by leveraging Spring Boot Actuator.

This page explains how to enable Spring Boot Actuator in the CMS application.

Prerequisites

To use this feature, your implementation project must use Bloomreach Experience Manager version 14.6.0 or later.

Instructions

Add Maven dependencies

Open cms-dependencies/pom.xml and add the following dependencies:

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-actuator</artifactId>
      <version>${spring-boot.version}</version>
      <exclusions>
        <exclusion>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-logging</artifactId>
        </exclusion>
      </exclusions>
    </dependency>

    <dependency>
      <groupId>io.micrometer</groupId>
      <artifactId>micrometer-registry-prometheus</artifactId>
      <version>1.5.5</version>
    </dependency>
    <dependency>
      <groupId>io.micrometer</groupId>
      <artifactId>micrometer-registry-jmx</artifactId>
      <version>1.5.5</version>
      <exclusions>
        <exclusion>
          <groupId>org.slf4j</groupId>
          <artifactId>slf4j-api</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
Please note that spring-boot-starter-logging and slf4j-api dependencies should be excluded.

The dependencies above add support for Spring Boot Actuator and the Micrometer framework.

Create Spring Boot configuration

Create a new file src/main/java/org/bloomreach/xm/cms/AppConfiguration.java with the following contents:

package org.bloomreach.xm.cms;

import javax.naming.NamingException;
import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.boot.actuate.jdbc.DataSourceHealthIndicator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.jndi.JndiObjectFactoryBean;

@Configuration
@PropertySource(value = "classpath:settings.properties")
public class AppConfiguration {

    @Value("${app.datasource.name}")
    String datasourceName;

    @Bean(destroyMethod = "")
    DataSource jndiDataSource() throws IllegalArgumentException, NamingException {
        final JndiObjectFactoryBean bean = new JndiObjectFactoryBean();
        bean.setJndiName("java:comp/env/jdbc/" + datasourceName);
        bean.afterPropertiesSet();
        return (DataSource) bean.getObject();
    }

    @Bean
    HealthIndicator dbHealthIndicator(final DataSource dataSource) {
        return new DataSourceHealthIndicator(dataSource, "SELECT 1");
    }

}
@PropertySource(value = "classpath:settings.properties") points to the property file which contains additional configuration.
Any Java-based configuration located at org.bloomreach.xm.cms will be auto located and used by Spring Boot due to framework conventions.

Create properties File

Create a new file src/main/resources/settings.properties with the following contents:

management.endpoint.health.probes.enabled=true
management.endpoint.health.show-details=always
management.endpoints.web.exposure.include=*

app.datasource.name=brxm

The sample configuration above enables health probes and exposes all actuator's endpoints. For further information please refer to Spring Boot Actuator documentation.

Please note that app.datasource.name property should point to a datasource name used in your CMS setup.

Rebuild and start the project using cargo profile

Rebuild and start the project.

Access http://localhost:8080/cms/actuator. You should see Spring Boot Actuator based page.

Did you find this page helpful?
How could this documentation serve you better?
On this page
    Did you find this page helpful?
    How could this documentation serve you better?