如何从Camunda流程引擎创建服务对象?

huangapple go评论68阅读模式
英文:

How to create services objects from Camunda process Engine?

问题

如何在Camunda的流程引擎中创建类似于userServicetaskService的对象?
我通常使用以下方法:

@Inject
private TaskService taskService;

或者

ProcessEngines.getDefaultProcessEngine().getTaskService();

对于大型项目是否有更好或更正确的方法?

英文:

How you create Objects like userService or taskService from process engine in Camunda?
my way is this:

@Inject
private TaskService taskService;

or

ProcessEngines.getDefaultProcessEngine().getTaskService();

Is there a better or more correct way for large projects?

答案1

得分: 2

将服务注入bean中是可以的。这是最简单的方式,可以让你享受Spring Beans的好处。

推荐使用基于构造函数的注入,而不是字段注入(例如:https://stackoverflow.com/questions/40737720/constructor-injection-vs-field-injection),以便更容易进行测试并检测循环依赖。

英文:

Simply injecting the service you need in the bean is fine. It is the simplest way and gives you the benefits of Spring Beans.

Prefer constructor based injection over field injection (e.g. https://stackoverflow.com/questions/40737720/constructor-injection-vs-field-injection) for easier testing and detection for cyclic dependencies.

huangapple
  • 本文由 发表于 2023年5月7日 14:28:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/76192494.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定