SpringBoot - activiti - 注入 org.activiti.engine.TaskService

SpringBoot - activiti - Injecting org.activiti.engine.TaskService

我创建了这个 class:

public class ActivitiWorkflowService  {
    

    private final TaskService taskService;

..
}

但是我在初始化项目时遇到了这个问题:

     No qualifying bean of 
type 'org.activiti.engine.TaskService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}

我希望您的 class 具有如下构造函数:

public class ActivitiWorkflowService  {
    

    private final TaskService taskService;

    public ActivitiWorkflowService(TaskService taskService) {
        this.taskService = taskService;
    }
}

您收到的错误是因为 Spring 无法将此 class 自动连接到 ActivitiWorkflowService - 它可能未在 Spring 上下文中定义。

根据您使用的配置,您可以:

使用 @Component@Service 注释定义 class 并让 @ComponentScan 完成它的工作:

@Component //@Service
public TaskService {
...
}

或者如果您正在使用 @Configuration class 定义类型为 TaskService

的 bean
@Configuration
public class AppConfig {
    @Bean
    public TaskService taskService() {
         return new TaskService();
    }
    
    @Bean
    public ActivitiWorkflowService activitiWorkflowService(TaskService taskService) {
        return new ActivitiWorkflowService(taskService);
    }
}