如何在SpringWebFlow + SpringBoot中解析静态资源?

时间:2019-05-21 11:59:47

标签: java spring spring-boot spring-webflow

我有这个项目结构
-> src / main / java

-> src / main / resources / static / myFolder / css / common.css

我有此配置类

@Configuration
public class WebFlowConfig extends AbstractFlowConfiguration {

@Autowired
private LocalValidatorFactoryBean localValidatorFacotryBean;

@Bean
public FlowDefinitionRegistry flowRegistry() {
    return getFlowDefinitionRegistryBuilder()
            .setBasePath("classpath:flow")
            .addFlowLocationPattern("/myflows/myflow1.xml")
            .addFlowLocationPattern("/myflows/myflow2.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() {
    FlowHandlerMapping handlerMapping = new FlowHandlerMapping();
    handlerMapping.setOrder(-1);
    handlerMapping.setFlowRegistry(this.flowRegistry());
    return handlerMapping;
}

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

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

@Bean
@Description("Thymeleaf AJAX view resolver for Spring WebFlow")
public AjaxThymeleafViewResolver thymeleafViewResolver() {
    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() {
    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() {
    SpringTemplateEngine templateEngine = new SpringTemplateEngine();
    templateEngine.setTemplateResolver(this.templateResolver());
    return templateEngine;
}

我总是会收到此错误,在DispatcherServlet中名称为'dispatcherServlet'的URI [/static/common.css]的HTTP请求中找不到映射

我总是会收到此错误,看来像<link rel = "stylesheet" href = "/ static / myFolder / common.css" />这样的标签已被解析为html

0 个答案:

没有答案