2017-04-05 2 views
0

을 프로필 : 개발, 테스트, ... 질문은등록 서로 다른 흐름이 서로 다른 봄 프로파일가 내 응용 프로그램에서

, 활성화에 따라 흐름을 등록하는 방법은 무엇입니까 봄 프로필?

예를 들어 flow : 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="flowRegistry" flow-builder-services="flowBuilderServices"> 
    <webflow:flow-location path=".../aFlow.xml" /> 
    <webflow:flow-location path=".../bFlow.xml" /> 
</webflow:flow-registry> 

배경 같은 것을 원하는 같은 : 봄 프로파일 개발 인 경우 bFlow.xml에 액세스 할 수 없습니다. 스프링 프로파일 테스트가 활성화되면 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> 

사전에 감사!

답변

0

내 문제에 대해 두 가지 해결책을 찾았습니다.

다음과 같은 초기 상황을 가정합니다. 테스트라는 스프링 프로파일이 있습니다. 플로우 aFlow.xml과 플로우 bFlow.xml이 있습니다. 프로파일 테스트가 활성화 된 경우에만 bFlow를 등록하고 어떤 프로파일이 활성 상태이든지 관계없이 aFlow를 등록하려고합니다. 제 생각 번째에서

@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(); 
    } 
} 

:

<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> 

제 2 용액은 유동 레지스트리의 스프링 자바 기반 구성을 사용

제 용액 유동 레지스트리의 XML 기반 구성을 사용 두 개의 다른 위치에서 동일한 ID를 사용하지 않기 때문에 솔루션이 더 좋습니다.