首先将Activiti嵌入API类型的应用程序以在该应用程序中使用是可行的,还是应该独立运行Activiti?
以下错误是由于bean定义引起的,但我不确定应在何处定义bean,以及如何定义-如果这是版本6的正确方法。Springhboot2的标准是在Java中注释bean,而不是在xml上下文中< / p>
git config --global user.name "github userID"
git clone "URL from github link copied earlier"
代码:
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-04-10 21:17:43.924 ERROR 19516 --- [ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Field runtimeService in ma.cvmeeting.workflow.WorkflowApplication$MyrestController required a bean of type 'org.activiti.engine.RuntimeService' that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type 'org.activiti.engine.RuntimeService' in your configuration.
Process finished with exit code 0
pom.xml:
import org.activiti.engine.RuntimeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
public class WorkflowApplication {
public static void main(String[] args) {
SpringApplication.run(WorkflowApplication.class, args);
}
@RestController
public static class MyrestController{
@Autowired
private RuntimeService runtimeService;
@GetMapping("/start-process")
public String startProcess() {
runtimeService.startProcessInstanceByKey("Potulerauneoffre");
return "Process started. Number of currently running"
+ "process instances = "
+ runtimeService.createProcessInstanceQuery().count();
}
}
答案 0 :(得分:1)
将引擎嵌入基于Spring的应用程序中时,有两种初始化引擎的方法:
1.)让spring为您初始化它,以便您无需任何配置即可立即使用所有引擎服务。这需要activiti-spring-boot-starter
作为依赖项。
2.)您可以自行初始化引擎,并提供@Configuration
类中的服务bean。为此,您仅需要activiti-engine
核心作为依赖项
由于尝试第二种方法而导致应用程序找不到RuntimeService
的原因,请在pom.xml
中添加以下依赖项并删除引擎
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring-boot-starter</artifactId>
</dependency>
您应该遵循documentation以获得更多帮助。
答案 1 :(得分:1)
如果您打算使用spring boot 2.x和使用新的API,我们建议使用activiti 7 core。如果您想参与新的API和项目计划,这是个好时机
答案 2 :(得分:0)
您可以编写一个@Configuration类并定义Activiti服务,如下所示:
@Configuration
public class ActivityConfig {
@Autowired
DataSource dataSource;
@Bean
public DataSourceTransactionManager getTransactionManager() {
return new DataSourceTransactionManager(dataSource);
}
@Bean
public ProcessEngineConfigurationImpl getProcessEngineConfiguration() {
SpringProcessEngineConfiguration res = new SpringProcessEngineConfiguration();
res.setDataSource(dataSource);
res.setTransactionManager(getTransactionManager());
return res;
}
@Bean
public ProcessEngineFactoryBean getProcessEngine() {
ProcessEngineFactoryBean res = new ProcessEngineFactoryBean();
res.setProcessEngineConfiguration(getProcessEngineConfiguration());
return res;
}
@Bean
public RepositoryService getRepositoryService() throws Exception {
return getProcessEngine().getObject().getRepositoryService();
}
@Bean
public FormService getFormService() throws Exception {
return getProcessEngine().getObject().getFormService();
}
@Bean
public TaskService getTaskService() throws Exception {
return getProcessEngine().getObject().getTaskService();
}
@Bean
public RuntimeService getRuntimeService() throws Exception {
return getProcessEngine().getObject().getRuntimeService();
}
@Bean
public HistoryService getHistoryService() throws Exception {
return getProcessEngine().getObject().getHistoryService();
}
@Bean
public IdentityService getIdentityService() throws Exception {
return getProcessEngine().getObject().getIdentityService();
}
}