You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can check and run the [full example source code here](https://github.com/salaboy/dapr-spring-boot-docs-examples).
294
294
295
-
## Using Dapr Workflows with Spring Boot
296
-
297
-
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.
298
-
299
-
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.
300
-
301
-
In order to enable the automatic bean discovery you can annotate your `@SpringBootApplication` with the `@EnableDaprWorkflows` annotation:
302
-
303
-
```
304
-
@SpringBootApplication
305
-
@EnableDaprWorkflows
306
-
public class MySpringBootApplication {}
307
-
```
308
-
309
-
By adding this annotation, all the `WorkflowActivity`s will be automatically managed by Spring and registered to the workflow engine.
310
-
311
-
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`:
312
-
313
-
```
314
-
public class MyWorkflowActivity implements WorkflowActivity {
315
-
316
-
@Autowired
317
-
private RestTemplate restTemplate;
318
-
```
319
-
320
-
You can also `@Autowired` the `DaprWorkflowClient` to create new instances of your workflows.
321
-
322
-
```
323
-
@Autowired
324
-
private DaprWorkflowClient daprWorkflowClient;
325
-
```
326
-
327
-
This enable applications to schedule new workflow instances and raise events.
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.
340
-
341
295
342
296
## Next steps
343
297
344
298
Learn more about the [Dapr Java SDK packages available to add to your Java applications](https://dapr.github.io/java-sdk/).
345
299
300
+
Check the How To guide for [Dapr Workflows using Spring Boot and Testcontainers for a local workflow development experience](sb-workflows-howto.md).
Following the same approach that we used for Spring Data and Spring Messaging, the [`dapr-spring-boot-starter`](_index.md) brings Dapr Workflow integration for Spring Boot users.
4
+
5
+
With Dapr Workflows you define complex orchestrations (workflows) in (Java) code. The Dapr Spring Boot Starter makes your life easier by managing `Workflow`s and `WorkflowActivity`s as Spring beans.
6
+
7
+
In order to enable the automatic bean discovery you can annotate your `@SpringBootApplication` with the `@EnableDaprWorkflows` annotation:
8
+
9
+
```
10
+
@SpringBootApplication
11
+
@EnableDaprWorkflows
12
+
public class MySpringBootApplication {
13
+
...
14
+
}
15
+
```
16
+
17
+
By adding this annotation, all the `Workflow`s and `WorkflowActivity`s beans will be automatically discovered by Spring and registered to the workflow engine.
18
+
19
+
## Creating Workflows and Activities
20
+
21
+
Inside your Spring Boot application you can define as many workflows as you want. You do that by creating new implementations of the `Workflow` interface.
22
+
23
+
```
24
+
@Component
25
+
public class MyWorkflow implements Workflow {
26
+
27
+
@Override
28
+
public WorkflowStub create() {
29
+
return ctx -> {
30
+
<WORKFLOW LOGIC>
31
+
};
32
+
}
33
+
34
+
}
35
+
```
36
+
37
+
From inside your workflow definitions, you can perform service to service interactions, schedule timers or receive external events.
38
+
39
+
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`:
40
+
41
+
```
42
+
@Component
43
+
public class MyWorkflowActivity implements WorkflowActivity {
44
+
45
+
@Autowired
46
+
private RestTemplate restTemplate;
47
+
```
48
+
49
+
## Creating and interacting with Workflows
50
+
51
+
52
+
To create and interact with Workflow instances you need to use the `DaprWorkflowClient` that you can also `@Autowired`.
53
+
54
+
```
55
+
@Autowired
56
+
private DaprWorkflowClient daprWorkflowClient;
57
+
```
58
+
59
+
Applications can now schedule new workflow instances and raise events.
[Check a full example here](https://github.com/dapr/java-sdk/blob/master/spring-boot-examples/workflows/patterns/src/main/java/io/dapr/springboot/examples/wfp/chain/ChainWorkflow.java)
72
+
73
+
74
+
75
+
## Next Steps & Resources
76
+
77
+
Check the blog post from [Baeldung covering Dapr Workflows and Dapr Pubsub](https://www.baeldung.com/dapr-workflows-pubsub) with a full working example.
78
+
79
+
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.
0 commit comments