如何在Spring Web Flow中自定义执行密钥

时间:2019-04-09 15:28:51

标签: java spring spring-webflow

我正在尝试更改spring网络流url,以将执行参数隐藏在路径内。我创建了自己的FlowUrlHandler,将执行和快照值追加为路径的最后一个元素,但是当我尝试使用该应用程序时如果启动流失败,因为有人说密钥格式不正确(看起来不像e1s1, )。我调试到FlowExecutionKeyFactory似乎可以适应我的需要,但是我无法找到一种方法来通过java config进行自定义。 这是我的webflow配置

@Configuration
public class WebflowConfig extends AbstractFlowConfiguration {

  @Autowired
  private LocalValidatorFactoryBean localValidatorFacotryBean;

  @Bean
  public FlowDefinitionRegistry flowRegistry() {
    return getFlowDefinitionRegistryBuilder() //
        .setBasePath("classpath:flows") //
        .addFlowLocationPattern("/**/*-flow.xml") //
        .setFlowBuilderServices(this.flowBuilderServices()) //
        .build();
  }

  @Bean
  public FlowExecutor flowExecutor() {
    return getFlowExecutorBuilder(this.flowRegistry()) //
        .build();
  }

  @Bean
  public FlowBuilderServices flowBuilderServices() {
    return getFlowBuilderServicesBuilder() //
        .setViewFactoryCreator(this.mvcViewFactoryCreator()) // Important!
        .setValidator(this.localValidatorFacotryBean).build();
  }
  // ----------------------------------------------------------

  @Bean
  public FlowHandlerMapping flowHandlerMapping() {
    final FlowHandlerMapping handlerMapping = new FlowHandlerMapping();
    handlerMapping.setOrder(-1);
    handlerMapping.setFlowRegistry(this.flowRegistry());
    return handlerMapping;
  }

  @Bean
  public FlowHandlerAdapter flowHandlerAdapter() {
    final FlowHandlerAdapter handlerAdapter = new FlowHandlerAdapter();
    handlerAdapter.setFlowExecutor(this.flowExecutor());
    handlerAdapter.setSaveOutputToFlashScopeOnRedirect(true);
    handlerAdapter.setFlowUrlHandler(pathBasedFlowUrlHandler());
    return handlerAdapter;
  }

  @Bean
  public FlowUrlHandler pathBasedFlowUrlHandler() {
    return new PathBasedFlowUrlHandler();
  }

  @Bean
  public ViewFactoryCreator mvcViewFactoryCreator() {
    final MvcViewFactoryCreator factoryCreator = new MvcViewFactoryCreator();
    factoryCreator.setViewResolvers(Collections.singletonList(this.thymeleafViewResolver()));
    factoryCreator.setUseSpringBeanBinding(true);
    return factoryCreator;
  }

  @Bean
  @Description("Thymeleaf AJAX view resolver for Spring WebFlow")
  public AjaxThymeleafViewResolver thymeleafViewResolver() {
    final AjaxThymeleafViewResolver viewResolver = new AjaxThymeleafViewResolver();
    viewResolver.setViewClass(FlowAjaxThymeleafView.class);
    viewResolver.setTemplateEngine(this.templateEngine());
    viewResolver.setCharacterEncoding("UTF-8");
    return viewResolver;
  }

  @Bean
  @Description("Thymeleaf template resolver serving HTML 5")
  public ClassLoaderTemplateResolver templateResolver() {
    final ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
    templateResolver.setPrefix("templates/");
    templateResolver.setCacheable(false);
    templateResolver.setSuffix(".html");
    templateResolver.setTemplateMode("HTML5");
    templateResolver.setCharacterEncoding("UTF-8");
    return templateResolver;
  }

  @Bean
  @Description("Thymeleaf template engine with Spring integration")
  public SpringTemplateEngine templateEngine() {
    final SpringTemplateEngine templateEngine = new SpringTemplateEngine();
    templateEngine.setTemplateResolver(this.templateResolver());
    return templateEngine;
  }


}

0 个答案:

没有答案