获取Spring Webflow生成的FLOW ID的完整列表的最佳方法是什么?
这是我的配置:
<webflow:flow-registry id="flowRegistry"
flow-builder-services="flowBuilderServices"
base-path="/WEB-INF/pageFlows">
<webflow:flow-location-pattern value="/**/*-flow.xml"/>
</webflow:flow-registry>
[更新1]我应该澄清一点,我想在Java代码中执行此操作,而不是检查我的配置。
[更新2]回答:requestContext.getActiveFlow().getApplicationContext()
答案 0 :(得分:3)
可以通过在flow-registry中定义它们的方式来标识流ID列表。默认情况下,除非定义了注册表基本路径,否则将为流分配等于其文件名减去文件扩展名的注册表标识符。
让我用例子解释一下:
场景1: 未指定flow-location和base-path:
<webflow:flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices">
<webflow:flow-location path="/WEB-INF/pageFlows/example.xml" />
</webflow:flow-registry>
流程ID:示例
场景2: 未指定flow-location-pattern和base-path:
<webflow:flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices">
<webflow:flow-location-pattern value="/WEB-INF/pageFlows/**/*-flow.xml"/>
</webflow:flow-registry>
如果您有像/WEB-INF/pageFlows/example1-flow.xml,/WEB-INF/pageFlows/example2-flow.xml这样的流程,则流ID分别为:example1-flow,example2-flow。
场景3: 您指定了自己的ID:
<webflow:flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices">
<webflow:flow-location path="/WEB-INF/pageFlows/example.xml" id="myExampleId" />
</webflow:flow-registry>
Flow id:myExampleId
场景4: 指定了基本路径:
<webflow:flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices" base-path="/WEB-INF">
<webflow:flow-location path="/pageFlows/example.xml" />
</webflow:flow-registry>
现在将为流分配注册表标识符,该注册表标识符等于其基本路径和文件名之间的路径段。 Flow id:pageFlows
场景5: 指定了flow-location-pattern和base-path:
<webflow:flow-registry id="flowRegistry" base-path="/WEB-INF">
<webflow:flow-location-pattern value="/**/*-flow.xml" />
</webflow:flow-registry>
现在将为流分配注册表标识符,该注册表标识符等于其基本路径和文件名之间的路径段。 因此,如果您在WEB-INF中的/ pageFlows1 / example1,/ pageFlows2 / example2目录中有流,则流ID分别为:pageFlows1,pageFlows2。
编辑:
以编程方式获取流ID:
假设您的流控制器和flowexecutor定义如下所示在webflow-config xml文件中:
<bean name="flowController" class="org.springframework.webflow.executor.mvc.FlowController">
<property name="flowExecutor" ref="flowExecutor" />
</bean>
//flowRegistry is alredy mentioned in your question
<flow:executor id="flowExecutor" registry-ref="flowRegistry">
<flow:repository type="continuation" max-conversations="1" max-continuations="30" />
</flow:executor>
您可以检索注册如下的流定义ID: (我从一个扩展AbstractController的Controller中调用它,这就是为什么你看到getServletContext()方法)
ApplicationContext context =
(ApplicationContext)getServletContext().getAttribute(
DispatcherServlet.SERVLET_CONTEXT_PREFIX + "yourWebContextName");
FlowController controller = (FlowController)context.getBean("flowController");
FlowExecutorImpl flowExecutorImpl = (FlowExecutorImpl)controller.getFlowExecutor();
FlowDefinitionRegistryImpl flowDefinitionRegistryImpl = (FlowDefinitionRegistryImpl)flowExecutorImpl.getDefinitionLocator();
//Assuming you have log configured
log.info("Registered Flow Ids are:"+flowDefinitionRegistryImpl.getFlowDefinitionIds());
FlowController可以访问FlowExecutor(webflow的初始入口点)。 FlowExecutor可以访问flowDefinitionRegistry,其中所有流在注册请求之前都已注册。
希望这有帮助。