Google Cloud Platform

Calling Java developers: Spring Cloud GCP 1.0 is now generally available

Spring Cloud GCP is a project in the Spring Cloud family that helps Java developers build Spring Boot applications that consume Google Cloud Platform (GCP) services easily and idiomatically. We’re excited to announce the general availability of Spring Cloud GCP 1.0.

Developed in collaboration with the Spring Team at Pivotal, this project implements familiar Spring idioms and abstractions to bring the benefits of Spring and Spring Boot to Java developers using GCP services. This way, Spring Cloud lets Java developers write more maintainable applications with less boilerplate code and simpler configuration, and that are portable in a hybrid on-premises and cloud-based environment.

Spring Cloud GCP 1.0 includes the following Spring Boot starter integrations:

Spring Cloud

These Spring Boot integrations (or “starters”) automatically discover credentials from the Google Cloud SDK, the runtime environment (e.g., App Engine), or a custom location. In addition, these starters are integrated with Cloud Foundry and GCP Service Broker, so they can simply auto-configure services and access credentials from there.

For example, adding the Spring Cloud GCP Trace dependency automatically adds distributed tracing capability to your application and stores traces to Stackdriver Trace for analysis. If you add the Spring Cloud GCP Logging dependency, then log messages are stored in Stackdriver Logging with log correlation via the trace ID, as you can see here:

Spring Cloud Trace

What comes after Spring Cloud GCP 1.0?

We’re already working on more integrations based on community feedback and we’ve recently released Spring Cloud GCP 1.1.0.M1, which has a preview of Spring Data Cloud Spanner and support for Spring Cloud Config.

For example, here’s how to map a class to a Cloud Spanner table:

  @Table(name = "events")
public class Event {
	private String id;

	private String name;


Then, you can create a data access object using Spring Data repository. Note that this Spring Data repository is no different for Cloud Spanner as it is for another RDBMS. That means you can easily migrate between a traditional RDBMS and Cloud Spanner.

  public interface EventRepository extends
PagingAndSortingRepository<Event, String> {

You can easily read/write data from/to Cloud Spanner using the repository:

  // Saving a new Event Event(...));

// Find an Event by ID
Event event = eventRepository.findById(...);

// Find the first 20 events, sorted by name in ascending order
List<Event> events = eventRepository.findAll(
    PageRequest.of(1, 20, Sort.Direction.ASC, "name"));

Best of all, when using Spring Data REST, you can expose the repository as a RESTful service simply by using an annotation:

public interface EventRepository extends 
PagingAndSortingRepository<Event, String> {

Learn more about Spring Cloud GCP

There are a number of resources to learn more about Spring Cloud GCP to get you started quickly:

Also, be sure to check out the latest walkthrough of the Spring Cloud GCP project by Pivotal’s Josh Long and Google’s Ray Tsang at Google Cloud Next 2018.They'll take you through a whirlwind tour of Cloud SQL, Cloud Spanner, Stackdriver Trace, and Cloud Pub/Sub integrations.

As a bonus, at the end of the video you'll learn how to classify pictures of cats using AI.

Help us make Spring Cloud GCP better

We are working on Spring Cloud GCP because we want GCP to be a great place for Java developers to build and run Spring Boot applications. We’re looking for feedback on the project. Please contribute issues and feature requests on our spring-cloud-gcp GitHub repository. We also hope to see you at the SpringOne Platform conference in September 2018!