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:
$ git clone https://github.com/coherence-community/coherence-spring.git
$ cd coherence-spring
$ git switch main
You now have checked out all the code for Coherence Spring! The relevant demo code for the Spring Cloud Config demo is
under 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:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId> (1)
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId> (2)
</dependency>
| 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:
<dependency>
<groupId>com.oracle.coherence.spring</groupId>
<artifactId>coherence-spring-boot-starter</artifactId> (1)
<version>5.0.0</version>
</dependency>
<dependency>
<groupId>com.oracle.coherence.ce</groupId>
<artifactId>coherence</artifactId> (2)
<version>26.04</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId> (3)
</dependency>
| 1 | Provides all integration code, caching + autoconfiguration support |
| 2 | The Oracle Coherence dependency |
| 3 | The dependency to integrate with the Spring Cloud Config server |
| Coherence Spring does not bring in Coherence automatically. Coherence Spring 5.x applications must declare the supported Coherence CE dependency explicitly. |
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.
$ cd /path/to/git/repo
$ mkdir coherence-spring-config-repository
$ cd coherence-spring-config-repository
$ git init
Add a properties file called config-client.properties:
coherence.logging.severity-level=6 (1)
coherence.logging.destination=slf4j (2)
coherence.properties.coherence.cluster=Demo Cluster (3)
coherence.properties.coherence.member=Demo Cluster Member (4)
coherence.properties.coherence.management.remote=true (5)
coherence.properties.coherence.management=all (6)
coherence.properties.coherence.management.report.autostart=true (7)
coherence.properties.coherence.reporter.output.directory=/path/to/reports/ (8)
coherence.properties.coherence.management.report.configuration=/reports/report-all.xml (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-26.04.jar/reports |
For more options please see the following three chapters in the official Oracle Coherence reference guide:
The sample’s EventService uses Spring’s events cache; PersonService reads the
database. Its default configuration does not enable Hibernate second-level/query
caching or select the shipped Hibernate-oriented XML. The app packages exact,
non-executable payload metadata for Event, the two Hibernate persistent-set
classes observed in the cached creation result, and the JDBC java.sql.Timestamp
that can populate its date field after a database reload. See the sample README for the
packaged CloudConfigCacheIT, its isolated Config Server fixture and per-permission
negative controls. The shared compiler retains production parameter names for
the named cache key #id and implicit controller argument names. The integration
check requires annotated service and HTTP cache hits with zero SQL after a
controlled database change, plus eviction and database reload through both paths.
It does not qualify arbitrary populated association graphs.
2.2. Run the Demo Application
Please execute the following:
$ ./mvnw clean package -pl :coherence-spring-cloud-config-demo-server
$ cd samples/coherence-spring-cloud-config-demo/coherence-spring-cloud-config-demo-server/target
$ java -jar coherence-spring-cloud-config-demo-server-5.0.0.jar \n
--spring.cloud.config.server.git.uri=file:///path/to/git/repo
$ ./mvnw clean package -pl :coherence-spring-cloud-config-demo-app
$ cd samples/coherence-spring-cloud-config-demo/coherence-spring-cloud-config-demo-app/target
$ java -jar coherence-spring-cloud-config-demo-app-5.0.0.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:
coherence.logging.severity-level=5
coherence.logging.destination=log4j
coherence.log.level=5
coherence.log=log4j
| Please also see Coherence Support of the Spring Boot ConfigData API. |