springboot-activiti-org.activiti.engine.taskservice注入

sycxhyv7  于 2021-07-14  发布在  Java
关注(0)|答案(1)|浏览(335)

我创建了这个类:

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: {}
p8h8hvxi

p8h8hvxi1#

我希望您的类有一个构造函数,例如:

public class ActivitiWorkflowService  {

    private final TaskService taskService;

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

得到的错误是因为spring无法将此类自动关联到 ActivitiWorkflowService -它可能没有定义在 Spring 上下文。
根据您使用的配置,您可以:
用定义类 @Component 或者 @Service 注解和let @ComponentScan 做它的工作:

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

或者如果你正在使用 @Configuration 类定义类型的bean TaskService ```
@Configuration
public class AppConfig {
@Bean
public TaskService taskService() {
return new TaskService();
}

@Bean
public ActivitiWorkflowService activitiWorkflowService(TaskService taskService) {
    return new ActivitiWorkflowService(taskService);
}

}

相关问题