Spring Boot 1.4.0 MILESTONE 2 is out! This is a good time to tell you about the joint effort between Spring Boot team members and the Couchbase Java SDK team to offer a first class integration of Couchbase into Spring Boot :)

In Spring Boot 1.4.0, Couchbase becomes a first class citizen of the Spring Boot ecosystem!

Couchbase SDK Integration

Spring Boot now directly recognizes when you have the Couchbase SDK in your classpath. And when that’s the case, it instantiates a Cluster and a Bucket bean for you using autoconfiguration.

Spring Boot can pick up properties to further configure these core SDK classes, even the CouchbaseEnvironment!

The following bootstrapping properties are recognized:

Environment tuning (IO endpoints, SSL support and default sync API timeouts) are exposed through the following properties:

Now this is ⭐️⭐️⭐️⭐️⭐️ support!

WARNING: Note that in the previous milestone the bootstrapping properties were prefixed with ” spring.*data*.couchbase “, now becoming ” spring.couchbase “.

Spring Cache Implementation

The Spring Cache abstraction has a Couchbase 2.x implementation, couchbase-spring-cache.

Spring Boot now recognizes this cache implementation when both the Java SDK and the couchbase-spring-cache artifacts are on the classpath.

This integrates nicely with the previous section, seeing as the default underlying storage Bucket for the caches is the one autoconfigured by Spring Boot :)

NOTE: The cache implementation has been pulled out of the Spring Data Couchbase project into its own project (in Couchbase’s github repository), so that it could be used and released separately from Spring Data.

TIP: Don’t forget to at least configure the spring.couchbase.bootstrap-hosts property.

This implementation of the CacheManager allows for storing data from several caches into the same Couchbase bucket, by automatically prefixing the keys in Couchbase with the name of each cache.

The CouchbaseCacheManager will automatically reuse the Bucket autoconfigured by Spring Boot. By simply adding a property to declaratively list cache names, the corresponding caches will be pre-loaded:

Five-star support, we tell you!

You can even configure it to store data for different caches into multiple buckets. The caches can then be configured using a fluent builder pattern (eg. in a CacheManagerCustomizer). This CacheBuilder also allows you to further tune the caches, like setting a default expiration time:

This implementation can use views to selectively clear caches that are collocated in the same Bucket.

Finally, it supports dynamic creation of caches as they are requested. To activate that, simply omit to declare any cache name and just activate Couchbase caching with the relevant property:

This will use the Spring Boot autoconfigured Bucket as the default bucket for all dynamically created caches.

Fun with @Cacheable awaits ?

Spring Data Integration

Spring Data Couchbase 2.1.0 (release train Hopper) has included several modifications that makes integration with Spring Boot a breeze.

First the usual suspect: by default Spring Boot will autoconfigure Spring Data Couchbase to use the Bucket it created. This is made possible by having separated the core SDK configuration parts into a CouchbaseConfigurer class, while what is really specific to Spring Data is located in a new base class, AbstractCouchbaseDataConfiguration.

If you use only Spring Data, you can go ahead and continue using the AbstractCouchbaseConfiguration, which is now both a CouchbaseConfigurer and an AbstractCouchbaseDataConfiguration.

If you use Spring Boot however, it will autoconfigure a CouchbaseConfigurer. You can always tune your own AbstractCouchbaseDataConfiguration and inject the configurer in it.

Other Spring Data Couchbase Features

The 2.1.0 release also includes a few new features:

Conclusion

Go grab that ⭐️⭐️⭐️⭐️⭐️ MILESTONE!

As always, feedback is welcome (in the Spring Data issue tracker, Spring Boot issue tracker or on the Couchbase forums).

Happy Coding!

Author

Posted by Simon Basle, Software Engineer, Pivotal

Simon Basl_ is a Paris-based Software Engineer working in the Spring team at Pivotal. Previously, he worked in the Couchbase Java SDK team. His interests span software design aspects (OOP, design patterns, software architecture), rich clients, what lies beyond code (continuous integration, (D)VCS, best practices), and reactive programming. He is also an editor for the French version of InfoQ.com.

Leave a reply