I tested the Java Spring Web Flow 2.4 Java configuration function by modifying an existing project from xml configuration to JavaConfig. The XML version works, but JavaConfig does not. Every time I try to start a stream with the URL http: // localhost: 8080 / sia_p219_ch08_spring_web_flow_order_pizza_customer_flow_complete / pizza , it returns 404. There are no exceptions. The message "no request mapping found for ..." is not displayed on the console. The web page is displayed The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
The project is hosted on github , a working version of XML.
I think the problem is that the request URL does not call pizza stream ( /WEB-INF/flows/pizza/pizza-flow.xml).
Here are some snippets of code:
WebAppInitializer:
@Override
protected Class<?>[] getRootConfigClasses() {
return new Class<?>[] { RootConfig.class };
}
@Override
protected Class<?>[] getServletConfigClasses() {
return new Class<?>[] { WebConfig.class };
}
@Override
protected String[] getServletMappings() {
return new String[] { "/" };
}
RootConfig:
@Configuration
@Import({WebFlowConfig.class})
public class RootConfig {}
WebFlowConfig:
@Configuration
@ComponentScan({"pizza"})
public class WebFlowConfig extends AbstractFlowConfiguration {
static{
System.out.println("WebFlowConfig loaded");
}
@Autowired
private WebConfig webMvcConfig;
@Bean
public FlowDefinitionRegistry flowRegistry() {
return
getFlowDefinitionRegistryBuilder(flowBuilderServices())
.setBasePath("/WEB-INF/flows")
.addFlowLocationPattern("/**/*-flow.xml")
.build();
}
@Bean
public FlowExecutor flowExecutor(){
return getFlowExecutorBuilder(flowRegistry()).build();
}
@Bean
public FlowBuilderServices flowBuilderServices() {
return getFlowBuilderServicesBuilder()
.setViewFactoryCreator(mvcViewFactoryCreator())
.setDevelopmentMode(true)
.build();
}
@Bean
public MvcViewFactoryCreator mvcViewFactoryCreator() {
MvcViewFactoryCreator factoryCreator = new MvcViewFactoryCreator();
factoryCreator.setViewResolvers(Collections.singletonList(this.webMvcConfig.viewResolver()));
factoryCreator.setUseSpringBeanBinding(true);
return factoryCreator;
}
}
WebConfig
@Configuration
@EnableWebMvc
public class WebConfig extends WebMvcConfigurerAdapter {
static{
System.out.println("WebConfig loaded");
}
@Bean
public ViewResolver viewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/flows/");
resolver.setSuffix(".jsp");
return resolver;
}
@Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
configurer.enable();
}
JSP , github, .
, .