Java

Dapr offers a variety of packages to help with the development of Java applications. Using them you can create Java clients, servers, and virtual actors with Dapr.

Prerequisites

Import Dapr’s Java SDK

Next, import the Java SDK packages to get started. Select your preferred build tool to learn how to import.

For a Maven project, add the following to your pom.xml file:

  1. <project>
  2. ...
  3. <dependencies>
  4. ...
  5. <!-- Dapr's core SDK with all features, except Actors. -->
  6. <dependency>
  7. <groupId>io.dapr</groupId>
  8. <artifactId>dapr-sdk</artifactId>
  9. <version>1.10.0</version>
  10. </dependency>
  11. <!-- Dapr's SDK for Actors (optional). -->
  12. <dependency>
  13. <groupId>io.dapr</groupId>
  14. <artifactId>dapr-sdk-actors</artifactId>
  15. <version>1.10.0</version>
  16. </dependency>
  17. <!-- Dapr's SDK integration with SpringBoot (optional). -->
  18. <dependency>
  19. <groupId>io.dapr</groupId>
  20. <artifactId>dapr-sdk-springboot</artifactId>
  21. <version>1.10.0</version>
  22. </dependency>
  23. ...
  24. </dependencies>
  25. ...
  26. </project>

For a Gradle project, add the following to your build.gradle file:

  1. dependencies {
  2. ...
  3. // Dapr's core SDK with all features, except Actors.
  4. compile('io.dapr:dapr-sdk:1.10.0')
  5. // Dapr's SDK for Actors (optional).
  6. compile('io.dapr:dapr-sdk-actors:1.10.0')
  7. // Dapr's SDK integration with SpringBoot (optional).
  8. compile('io.dapr:dapr-sdk-springboot:1.10.0')
  9. }

If you are also using Spring Boot, you may run into a common issue where the OkHttp version that the Dapr SDK uses conflicts with the one specified in the Spring Boot Bill of Materials.

You can fix this by specifying a compatible OkHttp version in your project to match the version that the Dapr SDK uses:

  1. <dependency>
  2. <groupId>com.squareup.okhttp3</groupId>
  3. <artifactId>okhttp</artifactId>
  4. <version>1.10.0</version>
  5. </dependency>

Try it out

Put the Dapr Java SDK to the test. Walk through the Java quickstarts and tutorials to see Dapr in action:

SDK samplesDescription
QuickstartsExperience Dapr’s API building blocks in just a few minutes using the Java SDK.
SDK samplesClone the SDK repo to try out some examples and get started.
  1. import io.dapr.client.DaprClient;
  2. import io.dapr.client.DaprClientBuilder;
  3. try (DaprClient client = (new DaprClientBuilder()).build()) {
  4. // sending a class with message; BINDING_OPERATION="create"
  5. client.invokeBinding(BINDING_NAME, BINDING_OPERATION, myClass).block();
  6. // sending a plain string
  7. client.invokeBinding(BINDING_NAME, BINDING_OPERATION, message).block();
  8. }

Available packages

Client

Create Java clients that interact with a Dapr sidecar and other Dapr applications.

Workflow

Create and manage workflows that work with other Dapr APIs in Java.


Getting started with the Dapr client Java SDK

How to get up and running with the Dapr Java SDK

Workflow

How to get up and running with the Dapr Workflow extension