This section explains how to configure Coherence using Spring Cloud Config.

1. Overview

Spring Cloud Config provides support for externalized configuration in distributed systems. It integrates seamlessly with Spring Boot applications and allows you to externalize / centralize critical application properties. Spring Cloud Config provides numerous storage backends for your configuration data and as part of Coherence Spring we also provide a backend for Oracle Coherence.

Please familiarize yourself with the Spring Cloud Config reference documentation.

In this chapter we will cover two aspects of Coherence-specific support for Spring Cloud Config:

  • Configure Coherence and its Spring support using Spring Cloud Config

Let’s get started with an example to show the general functioning of Spring Cloud Config.

2. Demo

This demo is essentially the same as is used in the Quickstart chapter. However, we externalize some Coherence configuration using Spring Cloud Config. The source code for the demo is part of the Coherence Spring source code repository. Therefore, to get started, please clone its repository:

Clone the Spring Cloud Config demo project
 $ git clone
 $ cd coherence-spring

You now have checked out all the code for Coherence Spring! The relevant demo code for the Spring Cloud Config demo is under coherence-spring-samples/coherence-spring-cloud-config-demo/. The demo consists of 2 Maven modules:

  • coherence-spring-cloud-config-demo-server: Spring Cloud Config Server implementation

  • coherence-spring-cloud-config-demo-app: Main application

The Config Server is essentially using 2 dependencies:

    <artifactId>spring-cloud-config-server</artifactId>    (1)
    <artifactId>spring-boot-starter-security</artifactId>  (2)
1 Spring Cloud Config Server dependency
2 Provides rudimentary security for the exposed configuration REST endpoints using Spring Security

The demo client on the other hand will use the following dependencies:

    <artifactId>coherence-spring-boot-starter</artifactId> (1)
    <artifactId>coherence</artifactId>                     (2)
    <artifactId>spring-cloud-starter-config</artifactId>   (3)
1 Provides all integration code, caching + autoconfiguration support
2 The Oracle Coherence dependency
3 The dependency to integrate with the Spring Cloud Config server
We made the decision to not automatically bring in the Coherence dependencies. The main reason is that users can specify the version they need, either the Oracle Coherence CE (OSS) or the commercial version.

2.1. Configure the Demo Application

In order to run the demo, we first need to create a Git repository that will contain the configuration data.

Set up the Config Data
 $ cd /path/to/git/repo
 $ mkdir coherence-spring-config-repository
 $ cd coherence-spring-config-repository
 $ git init

Add a properties file called
 coherence.logging.severity-level=6                                           (1)
 coherence.logging.destination=slf4j                                          (2) Cluster                          (3) Cluster Member                    (4)                        (5)                                (6)              (7)   (8) (9)
1 -1 emits no log messages, 9 emits the most
2 Specifies the logger e.g. stdout, log4j, log4j2, slf4j
3 The name of the cluster
4 The name of the cluster member
5 Specifies whether this cluster node exposes its managed objects to remote MBean server. true or false
6 none means no MBean server is instantiated. all enables management of both local and remotely manageable cluster nodes.
7 true or false (default) Specifies whether the Reporter automatically starts when the node starts.
8 The output directory for generated reports. By default, reports are saved reports to the directory from which the cluster member starts.
9 You can control which reports are generated by specifying a different report group configuration file. The pre-defined reports are located at coherence-22.09.jar/reports

For more options please see the following three chapters in the official Oracle Coherence reference guide:

2.2. Run the Demo Application

Please execute the following:

Start the Spring Cloud Config Server
 $ ./mvnw clean package -pl :coherence-spring-cloud-config-demo-server
 $ cd coherence-spring-samples/coherence-spring-cloud-config-demo/coherence-spring-cloud-config-demo-server/target
 $ java -jar coherence-spring-cloud-config-demo-server-4.0.0-SNAPSHOT.jar \n
Start the Coherence Spring Application
 $ ./mvnw clean package -pl :coherence-spring-cloud-config-demo-app
 $ cd coherence-spring-samples/coherence-spring-cloud-config-demo/coherence-spring-cloud-config-demo-app/target
 $ java -jar coherence-spring-cloud-config-demo-app-4.0.0-SNAPSHOT.jar

Feel free to change configuration settings and see, once you restart the apps, how the behavior of the Coherence cluster changes.

3. Use Spring Cloud Config Server to Configure Coherence

The previously discussed demo application illustrated the main concepts of using Spring Cloud Config Server as a configuration backend for Oracle Coherence. For a general understanding of Spring Cloud Config Server, please consult the respective reference documentation.

Coherence Spring is essentially unaware of Spring Cloud Config Server. Coherence Spring merely takes advantage of Spring Boot’s configuration facilities. The main integration point for configuration between Spring and Oracle Coherence is the SpringSystemPropertyResolver class, which makes the properties of Spring’s Environment available to Oracle Coherence.

When using Spring Boot (and not just plain Spring Framework), we also provide the CoherenceProperties class. It provides means to expose Coherence Spring configuration options in a type-safe manner, to provide code completion via your IDE etc.

Providing dedicated CoherenceProperties support is work in progress.

Behind the scenes using CoherenceProperties.getCoherencePropertiesAsMap() will translate the explicit Spring Boot properties into the property format used by Oracle Coherence. It is important to note that you can always provide ANY Oracle Coherence property as well.

For instance the following properties are equivalent:

Equivalent Properties