Skip to content

Commit cf7405f

Browse files
salaboycicoyle
andauthored
adding spring boot workflows integration (#1195)
Co-authored-by: Cassie Coyle <[email protected]>
1 parent be5530f commit cf7405f

File tree

1 file changed

+48
-1
lines changed
  • daprdocs/content/en/java-sdk-docs/spring-boot

1 file changed

+48
-1
lines changed

daprdocs/content/en/java-sdk-docs/spring-boot/_index.md

+48-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ Besides the previous configuration (`DaprTestContainersConfig`) your tests shoul
122122
The Java SDK allows you to interface with all of the [Dapr building blocks]({{< ref building-blocks >}}).
123123
But if you want to leverage the Spring and Spring Boot programming model you can use the `dapr-spring-boot-starter` integration.
124124
This includes implementations of Spring Data (`KeyValueTemplate` and `CrudRepository`) as well as a `DaprMessagingTemplate` for producing and consuming messages
125-
(similar to [Spring Kafka](https://spring.io/projects/spring-kafka), [Spring Pulsar](https://spring.io/projects/spring-pulsar) and [Spring AMQP for RabbitMQ](https://spring.io/projects/spring-amqp)).
125+
(similar to [Spring Kafka](https://spring.io/projects/spring-kafka), [Spring Pulsar](https://spring.io/projects/spring-pulsar) and [Spring AMQP for RabbitMQ](https://spring.io/projects/spring-amqp)) and Dapr workflows.
126126

127127
## Using Spring Data `CrudRepository` and `KeyValueTemplate`
128128

@@ -277,6 +277,53 @@ public static void setup(){
277277

278278
You can check and run the [full example source code here](https://github.com/salaboy/dapr-spring-boot-docs-examples).
279279

280+
## Using Dapr Workflows with Spring Boot
281+
282+
Following the same approach that we used for Spring Data and Spring Messaging, the `dapr-spring-boot-starter` brings Dapr Workflow integration for Spring Boot users.
283+
284+
To work with Dapr Workflows you need to define and implement your workflows using code. The Dapr Spring Boot Starter makes your life easier by managing `Workflow`s and `WorkflowActivity`s as Spring beans.
285+
286+
In order to enable the automatic bean discovery you can annotate your `@SpringBootApplication` with the `@EnableDaprWorkflows` annotation:
287+
288+
```
289+
@SpringBootApplication
290+
@EnableDaprWorkflows
291+
public class MySpringBootApplication {}
292+
```
293+
294+
By adding this annotation, all the `WorkflowActivity`s will be automatically managed by Spring and registered to the workflow engine.
295+
296+
By having all `WorkflowActivity`s as managed beans we can use Spring `@Autowired` mechanism to inject any bean that our workflow activity might need to implement its functionality, for example the `@RestTemplate`:
297+
298+
```
299+
public class MyWorkflowActivity implements WorkflowActivity {
300+
301+
@Autowired
302+
private RestTemplate restTemplate;
303+
```
304+
305+
You can also `@Autowired` the `DaprWorkflowClient` to create new instances of your workflows.
306+
307+
```
308+
@Autowired
309+
private DaprWorkflowClient daprWorkflowClient;
310+
```
311+
312+
This enable applications to schedule new workflow instances and raise events.
313+
314+
```
315+
String instanceId = daprWorkflowClient.scheduleNewWorkflow(MyWorkflow.class, payload);
316+
```
317+
318+
and
319+
320+
```
321+
daprWorkflowClient.raiseEvent(instanceId, "MyEvenet", event);
322+
```
323+
324+
Check the [Dapr Workflow documentation](https://docs.dapr.io/developing-applications/building-blocks/workflow/workflow-overview/) for more information about how to work with Dapr Workflows.
325+
326+
280327
## Next steps
281328

282329
Learn more about the [Dapr Java SDK packages available to add to your Java applications](https://dapr.github.io/java-sdk/).

0 commit comments

Comments
 (0)