我需要在启动时通过 Java 代码删除工作流。我的代码在运行时正常工作,但如果我在启动时运行它会抛出异常。我应该怎么做才能通过 Java 代码在启动时删除工作流?
例如:
我的示例上下文.xml:
<bean id="my-example" class="MyExamle" init-method="init">
<property name="workflowService">
<ref bean="WorkflowService"/>
</property>
</bean>
MyExamle.java:
public class MyExamle {
...
private WorkflowService workflowService;
public void init() {
PropertyCheck.mandatory(this, "workflowService", workflowService);
AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<Integer>() {
@Override
public Integer doWork() throws Exception {
Integer count = 0;
WorkflowDefinition reviewDef = workflowService.getDefinitionByName(
"activiti$activitiReview"
);
List<WorkflowInstance> workflowInstanceList = workflowService.getActiveWorkflows(
reviewDef.getId()
);
count = workflowInstanceList.size();
for (WorkflowInstance workflowInstance : workflowInstanceList) {
workflowService.deleteWorkflow(
workflowInstance.getId()
);
}
return count;
}
}, AuthenticationUtil.getSystemUserName());
}
...
}
此代码抛出异常:org.alfresco.service.namespace.NamespaceException:命名空间前缀 wf 未映射到命名空间 URI
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mrem-extention-bootstartup' defined in URL [jar:file:/C:/Alfresco/tomcat/webapps/alfresco/WEB-INF/lib/moldavia-rem.jar!/alfresco/extension/mrem-bootstartup-context.xml]: Invocation of init method failed; nested exception is org.alfresco.service.namespace.NamespaceException: Namespace prefix wf is not mapped to a namespace URI
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1420)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:276)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
at org.alfresco.web.app.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:63)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4135)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4630)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:546)
at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:637)
at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:563)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:498)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1277)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:321)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:445)
at org.apache.catalina.core.StandardService.start(StandardService.java:519)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:581)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: org.alfresco.service.namespace.NamespaceException: Namespace prefix wf is not mapped to a namespace URI
at org.alfresco.service.namespace.QName.createQName(QName.java:99)
at org.alfresco.service.namespace.QName.createQName(QName.java:121)
at org.alfresco.repo.workflow.WorkflowQNameConverter.convertNameToQName(WorkflowQNameConverter.java:103)
at org.alfresco.repo.workflow.WorkflowQNameConverter.convertNameToQName(WorkflowQNameConverter.java:85)
at org.alfresco.repo.workflow.WorkflowQNameConverter.mapNameToQName(WorkflowQNameConverter.java:71)
at org.alfresco.repo.workflow.WorkflowObjectFactory.getTaskTypeDefinition(WorkflowObjectFactory.java:409)
at org.alfresco.repo.workflow.WorkflowObjectFactory.createTaskDefinition(WorkflowObjectFactory.java:209)
at org.alfresco.repo.workflow.activiti.ActivitiTypeConverter.getTaskDefinition(ActivitiTypeConverter.java:155)
at org.alfresco.repo.workflow.activiti.ActivitiTypeConverter.convert(ActivitiTypeConverter.java:144)
at org.alfresco.repo.workflow.activiti.ActivitiWorkflowEngine.getDefinitionByName(ActivitiWorkflowEngine.java:487)
at org.alfresco.repo.workflow.WorkflowServiceImpl.getDefinitionByName(WorkflowServiceImpl.java:342)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.alfresco.repo.security.permissions.impl.AlwaysProceedMethodInterceptor.invoke(AlwaysProceedMethodInterceptor.java:34)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:46)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:147)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at $Proxy71.getDefinitionByName(Unknown Source)
at ru.moldavia.alfresco.workflow.WorkflowFactory.removeAllActivitiReviewWorkflow(Unknown Source)
at ru.moldavia.alfresco.workflow.WAO.removeAllNotificationWorkflows(Unknown Source)
at ru.moldavia.alfresco.workflow.bootstartup.WorkflowBootstartupExtention.extend(Unknown Source)
at ru.moldavia.alfresco.bootstartup.ExtentionBootstartup.runExtentions(Unknown Source)
at ru.moldavia.alfresco.bootstartup.ExtentionBootstartup.init(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1544)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1485)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
... 37 more