Spring CredHub provides client-side support for storing, retrieving, and deleting credentials from a CredHub server running in a Cloud Foundry platform.

CredHub provides an API to securely store, generate, retrieve, and delete credentials of various types. Spring CredHub provides a Java binding for the CredHub API, making it easy to integrate Spring applications with CredHub.

Inject and Use CredHubTemplate

The CredHubTemplate is used to interact with CredHub, typically used through its CredHubOperations interface.

The following is an example of setting a new credential in CredHub:

public class MyApp {
  CredHubOperations credHubOperations;

  public void writeAndDeleteCredential() {
    PasswordCredentialRequest request =
        .name(new SimpleCredentialName("spring-credhub", "demo"))
        .value(new PasswordCredential("secret"))

    CredentialDetails<PasswordCredential> storedCredential =

    CredentialDetails<PasswordCredential> retrievedCredential =


The following is an example of generating a new credential in CredHub:

public class MyApp {
  CredHubOperations credHubOperations;

  public void generateCredential() {
    PasswordParametersRequest request =
        .name(new SimpleCredentialName("spring-credhub", "demo"))

    CredentialDetails<PasswordCredential> credential =


CredHub supports two authentication methods: mutual TLS and OAuth2.

Mutual TLS

Mutual TLS is the default authentication scheme used when no other authentication configuration is provided.

Mutual TLS support on Cloud Foundry requires the the Container Security Provider feature of the Java Buildpack. Applications using Spring CredHub should be deployed to Cloud Foundry using Java Buildpack 3.17 or greater, or 4.1 or greater.


The following configuration can be provided in a Spring Boot application using Spring CredHub (e.g. in application.yml) to enable OAuth2 authentication to a CredHub server.

      client-id: [OAuth2 client ID]
      client-secret: [OAuth2 client secret]
      access-token-uri: [OAuth2 token server endpoint]

Spring Boot Config

The recommended way to get started using Spring CredHub in your project is with a dependency management system. One of the snippets below can be copied and pasted into your build.

With Maven:


With Gradle:

dependencies {

Spring CredHub will auto configure a CredHubTemplate if you provide the spring.credhub.url property to your Spring Boot application.

Quick start

Bootstrap your application with Spring Initializr.


Each Spring project has its own; it explains in great details how you can use project features and what you can achieve with them.
2.0.0 M1 PRE Reference Doc. API Doc.
2.0.0 SNAPSHOT Reference Doc. API Doc.
1.0.1 GA Reference Doc. API Doc.