因为这个项目license问题无法开源,更多技术支持与服务请加入我的知识星球。
今天在新的jeecg-boot里加入下面的代码
/**
* 部门经理处理类
*
* @author nbacheng
* @date 2023-08-06
*/
@AllArgsConstructor
@Component("DepManagerHandler")
@DependsOn({"SpringContextUtils"})
public class DepManagerHandler {
//IFlowThirdService flowThirdService = SpringContextUtils.getBean(IFlowThirdService.class);
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.NullPointerException
at 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)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:955)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:929)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:591)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:732)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:409)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:308)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1300)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1289)
at org.jeecg.JeecgSystemApplication.main(JeecgSystemApplication.java:33)
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.jeecg.modules.flowable.listener.DepManagerHandler]: Constructor threw exception; nested exception is java.lang.NullPointerException
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:226)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:117)
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:306)
... 19 common frames omitted
Caused by: java.lang.NullPointerException: null
at org.jeecg.common.util.SpringContextUtils.getBean(SpringContextUtils.java:99)
at org.jeecg.modules.flowable.listener.DepManagerHandler.<init>(DepManagerHandler.java:31)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:213)
... 21 common frames omitted
后来在start模块里增加下面的初始化,以便先初始化jeecg-module-flowable的服务组件
<dependencies>
<!-- SYSTEM 系统管理模块 -->
<dependency>
<groupId>org.jeecgframework.boot</groupId>
<artifactId>jeecg-system-biz</artifactId>
<version>${jeecgboot.version}</version>
</dependency>
<!-- DEMO 示例模块 -->
<dependency>
<groupId>org.jeecgframework.boot</groupId>
<artifactId>jeecg-module-demo</artifactId>
<version>${jeecgboot.version}</version>
</dependency>
<!--流程模块-->
<dependency>
<groupId>org.jeecgframework.boot</groupId>
<artifactId>jeecg-module-flowable</artifactId>
<version>${jeecgboot.version}</version>
</dependency>
之后启动正常了。