Spring Web Flow and Spring MVC URL 404

瘦欲@ 提交于 2019-12-11 08:16:47

问题


I am currently using Spring MVC 4.0.5 and would like to use Spring Web Flow for some process oriented pages. However, I think there is still some problem with my configuration.

In the server logs:

2014-09-15 20:54:49,280 [localhost-startStop-1] DEBUG org.springframework.webflow.definition.registry.FlowDefinitionRegistryImpl  - Registering flow definition 'ServletContext resource [/WEB-INF/flows/registration/registration-flow.xml]' under id 'registration'

However, when accessing it, the log says

2014-09-15 20:54:49,820 [http-bio-8080-exec-2] DEBUG org.springframework.webflow.mvc.servlet.FlowHandlerMapping  - No flow mapping found for request with URI '/appContext/registration/'

Here is my configuration for the web flow

@Configuration
public class WebFlowConfig extends AbstractFlowConfiguration {

private Logger logger = Logger.getLogger(WebFlowConfig.class);

@Bean
@Autowired
public FlowExecutor flowExecutor(FlowDefinitionRegistry flowRegistry,
        PlatformTransactionManager txManager, SessionFactory sessionFactory) {
    return getFlowExecutorBuilder(flowRegistry)
            .addFlowExecutionListener(new SecurityFlowExecutionListener(),
                    "*")
            .addFlowExecutionListener(
                    new HibernateFlowExecutionListener(sessionFactory,
                            txManager), "*").build();
}

@Bean
@Autowired
public FlowDefinitionRegistry flowRegistry(
        FlowBuilderServices flowBuilderServices) {
    return getFlowDefinitionRegistryBuilder(flowBuilderServices)
            .setBasePath("/WEB-INF/flows")
            .addFlowLocationPattern("/**/*-flow.xml").build();
}

@Bean
@Autowired
public FlowBuilderServices flowBuilderServices(
        MvcViewFactoryCreator mvcViewFactoryCreator, Validator validator) {
    return getFlowBuilderServicesBuilder()
            .setViewFactoryCreator(mvcViewFactoryCreator)
            .setValidator(validator).setDevelopmentMode(true).build();
}

@Bean
@Autowired
public MvcViewFactoryCreator mvcViewFactoryCreator(
        InternalResourceViewResolver viewResolver) {
    MvcViewFactoryCreator factoryCreator = new MvcViewFactoryCreator();
    factoryCreator.setViewResolvers(Arrays.asList(viewResolver));
    return factoryCreator;
}

@Bean
@Autowired
public FlowHandlerMapping flowHandlerMapping(FlowDefinitionRegistry registry) {
    FlowHandlerMapping handlerMapping = new FlowHandlerMapping();
    handlerMapping.setOrder(-1);
    handlerMapping.setFlowRegistry(registry);
    return handlerMapping;
}

@Bean
@Autowired
public FlowHandlerAdapter flowHandlerAdapter(FlowExecutor executor) {
    FlowHandlerAdapter handlerAdapter = new FlowHandlerAdapter();
    handlerAdapter.setFlowExecutor(executor);
    handlerAdapter.setSaveOutputToFlashScopeOnRedirect(true);
    return handlerAdapter;
}
}

Hope that someone can help. Thanks.


回答1:


You are specifying FlowHandlerMapping in webflow config:

    Implementation of HandlerMapping that follows a simple convention 
    for creating URL path mappings from the ids of registered flow definitions. This 
    implementation returns a FlowHandler that invokes a flow if the current request 
    path matches the id of a flow in the configured FlowDefinitionRegistry.

The default FlowUrlHandler implementation for Spring Web Flow is DefaultFlowUrlHandler.

    Expects URLs to launch flow to be of this pattern:

    http://<host>/[app context path]/[app servlet path]/<flow path>

    The flow id is treated as the path info component of the request URL string. 
    If the path info is null, the servletPath will be used as the flow id. Also, if 
    the servlet path ends in an extension it will be stripped when calculating the flow id.
    The flow definition URL for the given flow id will be built by appending the 
    flow id to the base app context and servlet paths.

No flow mapping found for request with URI '/appContext/registration/'

Your path info must have been null and servlet mapping is something like: /appContext/registration/* resulting in flow id as /appContext/registration/ which is not registered. So check your servlet mapping.




回答2:


Remove MvcViewFactoryCreator Definition And .setViewFactoryCreator(mvcViewFactoryCreator)



来源:https://stackoverflow.com/questions/25849070/spring-web-flow-and-spring-mvc-url-404

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!