Coherence Spring 3.0.0 Released

Gunnar Hillert
Oracle Coherence
Published in
6 min readSep 9, 2021

--

Photo: Coastline of Kailua-Kona, Hawaiʻi

After many months of hard work, the Oracle Coherence team is delighted to announce the final release of Coherence Spring 3.0.0.

The Coherence Spring project simplifies the integration between Oracle Coherence and the Spring ecosystem including Spring Boot. The project provides many Coherence-specific implementations of Spring features such as Spring Data, Spring Session, Spring’s cache abstraction and much more.

Configuration

Coherence Spring 3.0.0 takes advantage of the new Coherence Bootstrap API, and together with its new auto-configuration support for Spring Boot, this leads to a vastly improved user-experience in getting you up and running quickly. While Coherence Spring can be easily used with just the Spring Framework, we recommend using Spring Boot and its auto-configuration support in most use-cases. By using Spring Boot, starting a Coherence cluster member within the same JVM becomes as easy as adding the Coherence Spring Boot Starter dependency to your project:

Without further configuration, CoherenceAutoConfiguration will kick in, bootstrap Coherence, and thus allowing you to start injecting Coherence dependencies into your Spring-managed classes using a rich set of available annotations, including:

For instance, the following usage will inject a Coherence NamedMap called people:

You can also inject other Coherence-managed objects such as:

Fine-grained customization of the configuration is of course possible if needed, e.g. with dedicated Spring Boot configuration properties to customize the integration of Coherence. Additionally, we have added support for Spring Boot’s Config API in order to allow you to import additional configuration data using Coherence as a store of such configuration data by using the Spring Boot property spring.config.import with the value prefix coherence:.

Coherence Event Listeners

Another feature we added is the support for Coherence server- and client-side events. As such, you can add Coherence event listeners with the @CoherenceEventListener annotation:

This example will listen to client-sideMapEvents for the map named people. Using the optional WhereFilter, the event listener will only be triggered for people older than 18 years of age using a CohQL expression.

Spring Data

Coherence Spring adds support for Spring Data repositories using the new Coherence Repository API which had been introduced in
Coherence CE 21.06. This allows you to use Spring Data with Coherence as a back-end data store for your entities. The only requirement is that the primary key property of your entity needs to be annotated with with either org.springframework.data.annotation.Id or javax.persistence.Id. Using Spring Data’s @Id annotation is preferred as that eliminates the requirement on the Java Persistence API as a project dependency.

Another addition is the Projection support, to retrieve partial views of your entities. We have added support for:

  • Interface-based Projections (open and closed projections)
  • Class-based Projections (DTO)
  • Dynamic Projections
  • Nullable Wrappers

Coherence Spring also supports Spring Data pagination as well as asynchronous repositories. Dedicated Spring Boot auto-configuration support is available as well. This removes the need to explicitly provide the @EnableCoherenceRepositories annotation, as the Coherence Spring Data auto-configuration support will automatically detect any Coherence repositories.

Caching

If you need to use Coherence for caching using Spring’s Cache abstraction, just add Spring’s @EnableCaching annotation, and CoherenceAutoConfiguration will add a CoherenceCacheManager to the Spring ApplicationContext.

Now you can take advantage of Spring’s Cache abstraction that is backed by Coherence and use the relevant Spring annotations such as @Cacheable, @CacheEvict, @CachePut.

JPA CacheLoader and CacheStore Support

In this release we also added dedicated support for database-backed caches using the Java Persistence API (JPA) and also taking advantage of Spring Data’s JPA Repository support. In order to make that happen we are basically injecting Spring beans into the Coherence cluster.

Coherence Spring provides a JpaRepositoryCacheLoader as well as a JpaRepositoryCacheStore implementation. Please see the respective reference documentation for details and also check out the new Cachestore sample application that is part of the source code repository.

Spring Session

An often asked-for-feature is Spring Session support. You can now use Coherence as a session repository. This enables clustered sessions without being tied to any application container specific solution.

In order to add Spring Session support to your Spring Boot application, simply add the coherence-spring-session dependency to your project in addition to the Coherence Spring Boot Starter and Coherence dependency.

With the coherence-spring-session dependency added, CoherenceSpringSessionAutoConfiguration will be triggered, setting up the relevant Spring Session infrastructure. Nonetheless, auto-configuration will back-off in certain situations:

  • When setting property coherence.spring.session.enabled to false
  • If you define a Spring Boot property spring.session.store-type. Any value will deactivate auto-configuration for Coherence Spring Session.

As part of the Coherence Spring source code repository, we also provide a dedicated sample application showcasing the Spring session support.

Coherence Messaging and Topics Support

Another feature that we have added is the Coherence Messaging and Topics Support, allowing you to develop message-driven applications backed by Coherence. In order to send messages, create a message publisher using the CoherencePublisher annotation:

Create a Coherence Publisher

The resulting ProductClient bean can be injected as a normal Spring bean dependency wherever it is needed. Reactive and non-blocking method definitions using Future, Mono, and Flux are supported as well. To consume messages, use the @CoherenceTopicListener annotation:

Create a Coherence Topic Listener

For further details and features, including how to define the commit behavior and how to forward messages with the @SendTo annotation, check out the Messaging with Coherence Topics chapter of the reference documentation.

Coherence Metrics

Last but not least, we now provide Spring Boot auto-configuration support for Coherence Metrics. Simply add the coherence-micrometer Maven dependency and Coherence metrics will be automatically exposed via Micrometer.

Documentation

In order to get started, we provide 100 pages of reference documentation that is available in HTML and PDF formats from the Coherence Spring project website. There you have access to the JavaDocs as well.

For an overview of features that cover prior milestone releases, please also see the following blog posts:

To see all release notes of the 3.0.0 release cycle:

Example Applications

The reference guide also provides documentation for various example applications that are part of the Coherence Spring source code repository. The following samples are provided:

  • A basic sample for Spring Boot as well as plain Spring Framework
  • Spring Session sample
  • Spring Boot integration with Hibernate using Coherence as a second-level cache
  • Spring Cloud Config demo
  • Coherence Cache Store sample

If this is not enough, please also check out our Coherence To Do List Example Application for Spring Boot in a separate repo. This application is a more complete example of the integration of Spring Boot and Coherence. On the front-end, it provides REST and GraphQL APIs using either a React-based front-end or a JavaFX client application. For the back-end, a Spring Data-based Coherence repository is used.

Apache-Compatible Licensing

Moreover, the entire project is open-source software (OSS). Coherence Spring is liberally licensed under the Universal Permissive License 1.0 (UPL 1.0), which is compatible with the Apache 2.0 license. This is also the same OSS license that governs Coherence CE.

Contribute to Coherence Spring!

We would love to hear from you! Please take Coherence Spring and Coherence CE for a spin! If you have questions, please join our Slack channel or ask questions on Stack Overflow. If you see missing features or if you have any other suggestions for improvement please contact us, e.g. via Twitter @OracleCoherence or feel free to file a GitHub issue. Contributions are always welcome!

A special thanks goes to Eddú Meléndez Gonzalez, who contributed to Coherence Spring for this release.

--

--

Gunnar Hillert
Oracle Coherence

Consulting Member of Technical Staff at Oracle for the Coherence team. Java Champion, former Spring team member, OSS committer, DevNexus co-founder.