欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 房产 > 家装 > 在jeecgboot3.6.3增加flowable功能是出现SpringUtils.getBean 空指针异常问题

在jeecgboot3.6.3增加flowable功能是出现SpringUtils.getBean 空指针异常问题

2025/6/19 9:10:50 来源:https://blog.csdn.net/qq_40032778/article/details/140021501  浏览:    关键词:在jeecgboot3.6.3增加flowable功能是出现SpringUtils.getBean 空指针异常问题
因为这个项目license问题无法开源,更多技术支持与服务请加入我的知识星球。

在新的jeecg-boot3.6.3里加入下面的代码

/*** 部门经理处理类** @author nbacheng* @date 2023-08-06*/
@AllArgsConstructor
@Component("DepManagerHandler")
@DependsOn({"SpringContextUtils"})
public class DepManagerHandler {RuntimeService runtimeService = SpringContextUtils.getBean(RuntimeService.class);IFlowThirdService flowThirdService = SpringContextUtils.getBean(IFlowThirdService.class);public List<String> getUsers(DelegateExecution execution) {List<String> assignUserName = new ArrayList<String>();FlowElement flowElement = execution.getCurrentFlowElement();if (ObjectUtil.isNotEmpty(flowElement) && flowElement instanceof UserTask) {UserTask userTask = (UserTask) flowElement;if ( ObjectUtil.isNotEmpty(userTask.getCandidateGroups())) {if(StringUtils.contains(userTask.getCandidateGroups().get(0),"DepManagerHandler")) {// 获取流程发起人ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(execution.getProcessInstanceId()).singleResult();String startUserId = processInstance.getStartUserId();// 获取部门负责人列表List<String> depIds = flowThirdService.getDepartIdsByUsername(startUserId);List<String> DepHeadlist = new ArrayList<String>();for(String depId: depIds) {List<String> depList = flowThirdService.getDeptHeadByDepId(depId);if(depList != null) {DepHeadlist.addAll(depList);}}// 部门负责人列表去重if(!DepHeadlist.isEmpty() ) {for (String str : DepHeadlist) {if (!assignUserName.contains(str)) {assignUserName.add(str);}}}}}}    return assignUserName;}
}

出现空指针的问题,如下


Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2024-06-23 10:17:27.770 [main] [1;31mERROR[0;39m [36morg.springframework.boot.SpringApplication:818[0;39m - Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'DepManagerHandler' defined in file [F:\codestudy\jeecg-boot-v3.6.3\jeecg-module-flowable\target\classes\org\jeecg\modules\flowable\listener\DepManagerHandler.class]: Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.jeecg.modules.flowable.listener.DepManagerHandler]: Constructor threw exception; nested exception is java.lang.NullPointerExceptionat org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:310)at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:291)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1372)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1222)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)

通过跟踪就是就是下面出错,以前在3.00的时候好像没有问题

RuntimeService runtimeService = SpringContextUtils.getBean(RuntimeService.class);

那就通过下面的方式修改

/*** 部门经理处理类** @author nbacheng* @date 2023-08-06*/
@AllArgsConstructor
@Component("DepManagerHandler")
public class DepManagerHandler {@ResourceSpringContextUtils springContextUtils;IFlowThirdService flowThirdService = SpringContextUtils.getBean(IFlowThirdService.class);RuntimeService runtimeService = SpringContextUtils.getBean(RuntimeService.class);public List<String> getUsers(DelegateExecution execution) {List<String> assignUserName = new ArrayList<String>();FlowElement flowElement = execution.getCurrentFlowElement();if (ObjectUtil.isNotEmpty(flowElement) && flowElement instanceof UserTask) {UserTask userTask = (UserTask) flowElement;if ( ObjectUtil.isNotEmpty(userTask.getCandidateGroups())) {if(StringUtils.contains(userTask.getCandidateGroups().get(0),"DepManagerHandler")) {// 获取流程发起人ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(execution.getProcessInstanceId()).singleResult();String startUserId = processInstance.getStartUserId();// 获取部门负责人列表List<String> depIds = flowThirdService.getDepartIdsByUsername(startUserId);List<String> DepHeadlist = new ArrayList<String>();for(String depId: depIds) {List<String> depList = flowThirdService.getDeptHeadByDepId(depId);if(depList != null) {DepHeadlist.addAll(depList);}}// 部门负责人列表去重if(!DepHeadlist.isEmpty() ) {for (String str : DepHeadlist) {if (!assignUserName.contains(str)) {assignUserName.add(str);}}}}}}    return assignUserName;}
}

这样启动就不会出现问题了。

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词