我试图从jsf启动activiti引擎
@ManagedBean(name = "activitiProcess")
@ViewScoped
public class ActivitiProcess implements Serializable {
private String filename = "D:/WORKSPACE/activiti1/src/main/resources/diagrams/MyProcess.bpmn";
public ActivitiProcess() {
}
public void startProcess() {
System.out.println("hello world");
try {
ProcessEngine engine = ProcessEngines.getDefaultProcessEngine(); //returns null
RepositoryService repositoryService = engine.getRepositoryService();
repositoryService.createDeployment().addInputStream("myProcess.bpmn20.xml", new FileInputStream(filename)).deploy();
RuntimeService runtimeService = engine.getRuntimeService();
ProcessDefinition definition = engine.getRepositoryService().createProcessDefinitionQuery().processDefinitionKey("myProcess").singleResult();
FormService formService = engine.getFormService();
// List<FormProperty> formList = formService.getStartFormData(definition.getId()).getFormProperties();
Map<String, String> formProperties = new HashMap<String, String>();
/* use the jsf variable instead */
formProperties.put("filePath", "D://somePath");
formService.submitStartFormData(definition.getId(), formProperties);
} catch (Exception e) {
e.printStackTrace();
}
}
}
引擎总是返回null,我读到activiti.cfg.xml文件应该在类路径中,我把文件放在web-inf / classes下但仍然,引擎返回null表示activiti可以' t初始化引擎,有什么想法吗?
答案 0 :(得分:1)
添加此
@Inject
private ProcessEngine engine;
如果要在容器内运行CDI Bean,则不允许使用new关键字。相反,你需要注入bean,容器就是这样做的 rest,意思是,容器是负责管理bean生命周期的容器:它创建实例;它摆脱了它。那么如果不能调用构造函数,如何初始化bean呢?好吧,容器在构造实例之后和销毁之前为你提供了一个句柄。