Search code examples
javaspringspring-bootalfrescoactiviti

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


I've created this class:

public class ActivitiWorkflowService  {
    

    private final TaskService taskService;

..
}

but I have this problem when init the project:

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

Solution

  • I expect that your class has a constructor such as:

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

    The error you are getting is because Spring cannot autowire this class to the ActivitiWorkflowService - it probably was not defined in the Spring context.

    Depending on the configuration you use you can either:

    Define class with @Component or @Service annotation and let @ComponentScan do its work:

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

    or if you are using @Configuration class define the bean of type TaskService

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