英文:
How to create services objects from Camunda process Engine?
问题
如何在Camunda的流程引擎中创建类似于userService
或taskService
的对象?
我通常使用以下方法:
@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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论