Java 根据弹簧外形注册不同的流量
在我的应用程序中有不同的spring配置文件:开发,测试 问题是,是否有一种方法可以根据激活的弹簧轮廓记录流量 例如,我有流:aFlow.xml,bFlow.xml 如果spring概要文件开发被激活,我希望Java 根据弹簧外形注册不同的流量,java,spring,spring-mvc,spring-webflow,Java,Spring,Spring Mvc,Spring Webflow,在我的应用程序中有不同的spring配置文件:开发,测试 问题是,是否有一种方法可以根据激活的弹簧轮廓记录流量 例如,我有流:aFlow.xml,bFlow.xml 如果spring概要文件开发被激活,我希望 <webflow:flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices"> <webflow:flow-location path=".../aFlow.xml" /&
<webflow:flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices">
<webflow:flow-location path=".../aFlow.xml" />
</webflow:flow-registry>
<webflow:flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices">
<webflow:flow-location path=".../aFlow.xml" />
<webflow:flow-location path=".../bFlow.xml" />
</webflow:flow-registry>
如果弹簧轮廓测试被激活,那么我想要
<webflow:flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices">
<webflow:flow-location path=".../aFlow.xml" />
</webflow:flow-registry>
<webflow:flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices">
<webflow:flow-location path=".../aFlow.xml" />
<webflow:flow-location path=".../bFlow.xml" />
</webflow:flow-registry>
背景:如果spring概要文件开发被激活,那么bFlow.xml可能无法访问。如果激活了spring概要文件测试,则应该可以访问aFlow.xml和bFlow.xml
目前我有以下解决方案。我定义
<webflow:flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices">
<webflow:flow-location path=".../aFlow.xml" />
</webflow:flow-registry>
<webflow:flow-registry id="flowRegistryTest" flow-builder-services="flowBuilderServices" parent="flowRegistry">
<webflow:flow-location path=".../bFlow.xml" />
</webflow:flow-registry>
并根据弹簧轮廓使用不同的FlowHandlerMapping:
<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping">
<property name="flowRegistry" ref="flowRegistry"/>
<property name="defaultHandler">
<!-- If no flow match, map path to a view to render; e.g. the "/intro" path would map to the view named
"intro" -->
<bean class="org.springframework.web.servlet.mvc.UrlFilenameViewController"/>
</property>
</bean>
<beans profile="test">
<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping" primary="true">
<property name="flowRegistry" ref="flowRegistryTest"/>
<property name="defaultHandler">
<!-- If no flow match, map path to a view to render; e.g. the "/intro" path would map to the view named
"intro" -->
<bean class="org.springframework.web.servlet.mvc.UrlFilenameViewController"/>
</property>
</bean>
</beans>
提前谢谢 我找到了两种解决我所说问题的方法 假设以下初始情况:您有一个名为test的spring概要文件。您有一个flow.xml流和一个flow.xml流。无论哪个配置文件处于活动状态,您都希望注册为低流量,并且仅当配置文件测试处于活动状态时才希望注册bFlow 第一个解决方案使用基于xml的流注册表配置:
<beans profile="!test">
<webflow:flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices">
<webflow:flow-location path=".../aFlow.xml"/>
</webflow:flow-registry>
</beans>
<beans profile="test">
<webflow:flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices">
<webflow:flow-location path=".../aFlow.xml"/>
<webflow:flow-location path=".../bFlow.xml"/>
</webflow:flow-registry>
</beans>
@Configuration
public class FlowRegistryConfiguration extends AbstractFlowConfiguration {
@Bean(name = "flowRegistry")
public FlowDefinitionRegistry flowDefinitionRegistry() {
FlowDefinitionRegistryBuilder builder = getFlowDefinitionRegistryBuilder(
(FlowBuilderServices) getApplicationContext().getBean("flowBuilderServices"))
.addFlowLocation(".../aFlow.xml");
List<String> activeProfiles = Arrays.asList(getApplicationContext().getEnvironment().getActiveProfiles());
if (activeProfiles.contains("test")) {
builder = builder.addFlowLocation(".../bFlow.xml");
}
return builder.build();
}
}
第二个解决方案使用基于spring java的流注册表配置:
<beans profile="!test">
<webflow:flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices">
<webflow:flow-location path=".../aFlow.xml"/>
</webflow:flow-registry>
</beans>
<beans profile="test">
<webflow:flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices">
<webflow:flow-location path=".../aFlow.xml"/>
<webflow:flow-location path=".../bFlow.xml"/>
</webflow:flow-registry>
</beans>
@Configuration
public class FlowRegistryConfiguration extends AbstractFlowConfiguration {
@Bean(name = "flowRegistry")
public FlowDefinitionRegistry flowDefinitionRegistry() {
FlowDefinitionRegistryBuilder builder = getFlowDefinitionRegistryBuilder(
(FlowBuilderServices) getApplicationContext().getBean("flowBuilderServices"))
.addFlowLocation(".../aFlow.xml");
List<String> activeProfiles = Arrays.asList(getApplicationContext().getEnvironment().getActiveProfiles());
if (activeProfiles.contains("test")) {
builder = builder.addFlowLocation(".../bFlow.xml");
}
return builder.build();
}
}
@配置
公共类FlowRegistryConfiguration扩展了AbstractFlowConfiguration{
@Bean(name=“flowRegistry”)
公共FlowDefinitionRegistry FlowDefinitionRegistry(){
FlowDefinitionRegistryBuilder=getFlowDefinitionRegistryBuilder(
(FlowBuilderServices)getApplicationContext().getBean(“FlowBuilderServices”))
.addFlowLocation(“…/aFlow.xml”);
List activeProfiles=Arrays.asList(getApplicationContext().getEnvironment().getActiveProfiles());
if(activeProfiles.contains(“测试”)){
builder=builder.addFlowLocation(“…/bFlow.xml”);
}
返回builder.build();
}
}
在我看来,第二种解决方案更好,因为您在两个不同的位置不使用相同的id