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, please select the dependencies below based on brxm version.

For brXM 16.x

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-actuator</artifactId>
  <version>${spring-boot.version}</version>
</dependency>
<dependency>
  <groupId>io.micrometer</groupId>
  <artifactId>micrometer-registry-prometheus</artifactId>
  <version>1.12.3</version>
</dependency>
<dependency>
  <groupId>io.micrometer</groupId>
  <artifactId>micrometer-registry-jmx</artifactId>
  <version>1.12.3</version>
</dependency>


For brXM 14.x & 15.x

    <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>
        <exclusion>
          <groupId>org.yaml</groupId>
          <artifactId>snakeyaml</artifactId>
        </exclusion>
      </exclusions>
    </dependency>

    <dependency>
      <groupId>io.micrometer</groupId>
      <artifactId>micrometer-registry-prometheus</artifactId>
      <!-- Note: on versions lower than 15.3.0, use version 1.5.5 -->
      <version>1.9.7</version> 
    </dependency>
    <dependency>
      <groupId>io.micrometer</groupId>
      <artifactId>micrometer-registry-jmx</artifactId>
       <!-- Note: on versions lower than 15.3.0, use version 1.5.5 -->
      <version>1.9.7</version>
      <exclusions>
        <exclusion>
          <groupId>org.slf4j</groupId>
          <artifactId>slf4j-api</artifactId>
        </exclusion>
      </exclusions>
    </dependency>

For all versions
If spring security dependencies are not present in project please add the following also.

    <dependency>
      <groupId>org.springframework.security</groupId>
      <artifactId>spring-security-web</artifactId>
      <version>${spring-security.version}</version>
    </dependency>

    <dependency>
      <groupId>org.springframework.security</groupId>
      <artifactId>spring-security-config</artifactId>
      <version>${spring-security.version}</version>
    </dependency>
Please note that spring-boot-starter-loggingslf4j-api and snakeyaml-1.x dependencies should be excluded.

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

Create Spring Boot configuration

In the CMS module, create a new file src/main/java/org/bloomreach/xm/cms/ActuatorConfiguration.java with the following contents, please chose the file based on your brxm version.

For brXM 16.x

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;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer;

@Configuration
@PropertySource(value = "classpath:actuator.properties")
// from 15.3.0 onwards, add this security annotation
@EnableWebSecurity
public class ActuatorConfiguration {

    @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");
    }

    // Note: with Spring Boot 2.7, there's tighter security by default so
    // from 15.3.0 onwards, add this method
    @Bean
    public WebSecurityCustomizer webSecurityCustomizer() {
        // allow all requests, please adjust if applicable
        return (web) -> web.ignoring().requestMatchers("/**");
    }
}

 

For brXM 14.x and 15.x

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;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer;

@Configuration
@PropertySource(value = "classpath:actuator.properties")
// from 15.3.0 onwards, add this security annotation
@EnableWebSecurity
public class ActuatorConfiguration {

    @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");
    }

    // Note: with Spring Boot 2.7, there's tighter security by default so
    // from 15.3.0 onwards, add this method
    @Bean
    public WebSecurityCustomizer webSecurityCustomizer() {
        // allow all requests, please adjust if applicable
        return (web) -> web.ignoring().antMatchers("/**");
    }
}
@PropertySource(value = "classpath:actuator.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/actuator.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=actuatorDS

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

Create a datasource if not present

Please note that app.datasource.name property should point to a JNDI datasource name used in your CMS setup, typically a <Resource> element in context.xml.
When running on Bloomreach Cloud, please reuse the repository datasource named "repositoryDS".

For running locally with Cargo, it's easiest to use an H2 database.

<Resource name="jdbc/actuatorDS" auth="Container" type="javax.sql.DataSource"
     maxTotal="100" maxIdle="10" initialSize="10" maxWaitMillis="10000"
     testWhileIdle="true" testOnBorrow="false" validationQuery="SELECT 1"
     timeBetweenEvictionRunsMillis="10000"
     minEvictableIdleTimeMillis="60000"
     username="sa" password=""
     driverClassName="org.h2.Driver"
     url="jdbc:h2:${repo.path}/brxm/actuator"/>

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?