activiti中实现TaskListener注入Spring的bean以及去除自带权限问题
实现TaskListener监听器,使用默认生成的代码,是无法在监听器里面注入我们需要的bean(@Autowired和@Resource获取到的bean都是null),这里做下笔记。
第一步
此时需要把bpmn中这样设置,sendDocumentStartListener是监听器的类名(在这里首字母要小写)
<userTask activiti:assignee="${assignee}" activiti:exclusive="true" id="_3" name="order_verify_1"> <extensionElements> <activiti:taskListener event="create" delegateExpression="${taskListenerImp}" /> </extensionElements> </userTask>
第二步
@Component public class TaskListenerImp implements TaskListener , JavaDelegate { @Autowired RuntimeService runtimeservice; @Override public void notify(DelegateTask delegateTask) { System.out.println(runtimeservice); } @Override public void execute(DelegateExecution var1){ } }
@SpringBootApplication( exclude = { org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration.class, org.springframework.boot.actuate.autoconfigure.security.servlet.ManagementWebSecurityAutoConfiguration.class } )
<!-- activiti工作流 --> <dependency> <groupId>org.activiti</groupId> <artifactId>activiti-spring-boot-starter</artifactId> <exclusions> <exclusion> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> </exclusion> </exclusions> <version>7.0.0.SR1</version> </dependency>