JAVA-3530 Move spring-mvc-webflow module
This commit is contained in:
7
spring-web-modules/spring-mvc-webflow/README.md
Normal file
7
spring-web-modules/spring-mvc-webflow/README.md
Normal file
@@ -0,0 +1,7 @@
|
||||
## Spring MVC WebFlow
|
||||
|
||||
This module contains articles about Spring MVC Web Flow
|
||||
|
||||
### Relevant Articles:
|
||||
|
||||
- [Guide to Spring Web Flow](https://www.baeldung.com/spring-web-flow)
|
||||
120
spring-web-modules/spring-mvc-webflow/pom.xml
Normal file
120
spring-web-modules/spring-mvc-webflow/pom.xml
Normal file
@@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>spring-mvc-webflow</artifactId>
|
||||
<version>0.1-SNAPSHOT</version>
|
||||
<name>spring-mvc-webflow</name>
|
||||
<packaging>war</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!-- Spring -->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-web</artifactId>
|
||||
<version>${org.springframework.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-webmvc</artifactId>
|
||||
<version>${org.springframework.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Spring Web Flow -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.webflow</groupId>
|
||||
<artifactId>spring-webflow</artifactId>
|
||||
<version>${spring.webflow}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- web -->
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
<version>${javax.servlet-api.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>jstl</artifactId>
|
||||
<version>${jstl.version}</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency> <!-- needed to bridge to slf4j for projects that use the log4j APIs directly -->
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>log4j-over-slf4j</artifactId>
|
||||
<version>${org.slf4j.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Test -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<version>${spring-boot-starter-test.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>spring-mvc-webflow</finalName>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.tomee.maven</groupId>
|
||||
<artifactId>tomee-maven-plugin</artifactId>
|
||||
<version>8.0.1</version>
|
||||
<configuration>
|
||||
<tomeeHttpPort>8080</tomeeHttpPort>
|
||||
<context>spring-mvc-webflow</context>
|
||||
<reloadOnUpdate>true</reloadOnUpdate>
|
||||
<tomeeClassifier>plume</tomeeClassifier>
|
||||
<synchronization>
|
||||
<extensions>
|
||||
<extension>.class</extension>
|
||||
</extensions>
|
||||
</synchronization>
|
||||
<args>-Xmx2048m -XX:PermSize=256m -Dtomee.serialization.class.blacklist=- -Dtomee.serialization.class.whitelist=*</args>
|
||||
<removeDefaultWebapps>true</removeDefaultWebapps>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
<version>${maven-war-plugin.version}</version>
|
||||
<configuration>
|
||||
<failOnMissingWebXml>false</failOnMissingWebXml>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<!-- Spring -->
|
||||
<org.springframework.version>5.0.1.RELEASE</org.springframework.version>
|
||||
|
||||
<!-- Spring Web Flow -->
|
||||
<spring.webflow>2.5.0.RELEASE</spring.webflow>
|
||||
|
||||
<httpcore.version>4.4.5</httpcore.version>
|
||||
<httpclient.version>4.5.2</httpclient.version>
|
||||
|
||||
<!-- Maven plugins -->
|
||||
<maven-resources-plugin.version>2.7</maven-resources-plugin.version>
|
||||
<cargo-maven2-plugin.version>1.6.1</cargo-maven2-plugin.version>
|
||||
<spring-boot-starter-test.version>1.5.10.RELEASE</spring-boot-starter-test.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.baeldung.servlet;
|
||||
|
||||
import javax.servlet.ServletRegistration.Dynamic;
|
||||
|
||||
import com.baeldung.spring.WebFlowConfig;
|
||||
import com.baeldung.spring.WebMvcConfig;
|
||||
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
|
||||
|
||||
public class WebInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
|
||||
|
||||
public WebInitializer() {
|
||||
super();
|
||||
}
|
||||
|
||||
// API
|
||||
protected Class<?>[] getRootConfigClasses() {
|
||||
return new Class<?>[] { WebMvcConfig.class, WebFlowConfig.class };
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getServletConfigClasses() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] getServletMappings() {
|
||||
return new String[] { "/" };
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void customizeRegistration(final Dynamic registration) {
|
||||
super.customizeRegistration(registration);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.baeldung.spring;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.webflow.config.AbstractFlowConfiguration;
|
||||
import org.springframework.webflow.definition.registry.FlowDefinitionRegistry;
|
||||
import org.springframework.webflow.engine.builder.support.FlowBuilderServices;
|
||||
import org.springframework.webflow.executor.FlowExecutor;
|
||||
import org.springframework.webflow.mvc.builder.MvcViewFactoryCreator;
|
||||
|
||||
@Configuration
|
||||
public class WebFlowConfig extends AbstractFlowConfiguration {
|
||||
|
||||
@Autowired
|
||||
private WebMvcConfig webMvcConfig;
|
||||
|
||||
@Bean
|
||||
public FlowDefinitionRegistry flowRegistry() {
|
||||
return getFlowDefinitionRegistryBuilder(flowBuilderServices()).addFlowLocation("/WEB-INF/flows/activation-flow.xml", "activationFlow").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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.baeldung.spring;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
import org.springframework.web.servlet.view.InternalResourceViewResolver;
|
||||
import org.springframework.web.servlet.view.JstlView;
|
||||
import org.springframework.webflow.mvc.servlet.FlowHandlerAdapter;
|
||||
import org.springframework.webflow.mvc.servlet.FlowHandlerMapping;
|
||||
|
||||
@EnableWebMvc
|
||||
@Configuration
|
||||
public class WebMvcConfig implements WebMvcConfigurer {
|
||||
|
||||
@Autowired
|
||||
private WebFlowConfig webFlowConfig;
|
||||
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
|
||||
}
|
||||
|
||||
@Bean
|
||||
public InternalResourceViewResolver viewResolver() {
|
||||
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
|
||||
viewResolver.setViewClass(JstlView.class);
|
||||
viewResolver.setPrefix("/WEB-INF/view/");
|
||||
viewResolver.setSuffix(".jsp");
|
||||
return viewResolver;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public FlowHandlerMapping flowHandlerMapping() {
|
||||
FlowHandlerMapping handlerMapping = new FlowHandlerMapping();
|
||||
handlerMapping.setOrder(-1);
|
||||
handlerMapping.setFlowRegistry(this.webFlowConfig.flowRegistry());
|
||||
return handlerMapping;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public FlowHandlerAdapter flowHandlerAdapter() {
|
||||
FlowHandlerAdapter handlerAdapter = new FlowHandlerAdapter();
|
||||
handlerAdapter.setFlowExecutor(this.webFlowConfig.flowExecutor());
|
||||
handlerAdapter.setSaveOutputToFlashScopeOnRedirect(true);
|
||||
return handlerAdapter;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:flow="http://www.springframework.org/schema/webflow-config"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/webflow-config
|
||||
http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.4.xsd
|
||||
http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
|
||||
|
||||
|
||||
<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping">
|
||||
<property name="flowRegistry" ref="activationFlowRegistry"/>
|
||||
</bean>
|
||||
|
||||
<flow:flow-builder-services id="flowBuilderServices"
|
||||
view-factory-creator="mvcViewFactoryCreator"/>
|
||||
|
||||
<bean id="mvcViewFactoryCreator" class="org.springframework.webflow.mvc.builder.MvcViewFactoryCreator">
|
||||
<property name="viewResolvers" ref="jspViewResolver"/>
|
||||
</bean>
|
||||
|
||||
<flow:flow-registry id="activationFlowRegistry" flow-builder-services="flowBuilderServices">
|
||||
<flow:flow-location id="activationFlow" path="/WEB-INF/flows/activation-flow.xml"/>
|
||||
</flow:flow-registry>
|
||||
|
||||
<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerAdapter">
|
||||
<property name="flowExecutor" ref="activationFlowExecutor"/>
|
||||
</bean>
|
||||
<flow:flow-executor id="activationFlowExecutor" flow-registry="activationFlowRegistry"/>
|
||||
|
||||
|
||||
</beans>
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
<configuration>
|
||||
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
|
||||
</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<logger name="org.springframework" level="WARN" />
|
||||
<logger name="org.springframework.transaction" level="WARN" />
|
||||
|
||||
<!-- in order to debug some marshalling issues, this needs to be TRACE -->
|
||||
<logger name="org.springframework.web.servlet.mvc" level="WARN" />
|
||||
|
||||
<root level="INFO">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</root>
|
||||
|
||||
</configuration>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<flow xmlns="http://www.springframework.org/schema/webflow"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/webflow
|
||||
http://www.springframework.org/schema/webflow/spring-webflow.xsd">
|
||||
|
||||
|
||||
<view-state id="activation">
|
||||
<transition on="activate" to="success"/>
|
||||
<transition on="cancel" to="failure"/>
|
||||
</view-state>
|
||||
|
||||
<view-state id="success" />
|
||||
|
||||
<view-state id="failure" />
|
||||
|
||||
</flow>
|
||||
@@ -0,0 +1,23 @@
|
||||
<html>
|
||||
<body>
|
||||
<h2>Hello World!</h2>
|
||||
<%--<a href="${flowExecutionUrl}">Start</a>--%>
|
||||
<%--<input type="submit" name="_eventId_success" value="Proceed" />--%>
|
||||
<%--<input type="submit" name="_eventId_failure" value="Cancel" />--%>
|
||||
|
||||
<form method="post" action="${flowExecutionUrl}">
|
||||
|
||||
<input type="hidden" name="_eventId" value="activate">
|
||||
<input type="submit" value="Proceed" />
|
||||
|
||||
</form>
|
||||
|
||||
<form method="post" action="${flowExecutionUrl}">
|
||||
|
||||
<input type="hidden" name="_eventId" value="cancel">
|
||||
<input type="submit" value="Cancel" />
|
||||
|
||||
</form>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,5 @@
|
||||
<html>
|
||||
<body>
|
||||
<h2>Activation Failed</h2>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,7 @@
|
||||
<html>
|
||||
<head></head>
|
||||
|
||||
<body>
|
||||
<h1>This is the body of the sample view</h1>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,5 @@
|
||||
<html>
|
||||
<body>
|
||||
<h2>Activation Successful!</h2>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.baeldung;
|
||||
|
||||
import com.baeldung.spring.WebFlowConfig;
|
||||
import com.baeldung.spring.WebMvcConfig;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = {WebFlowConfig.class, WebMvcConfig.class})
|
||||
@WebAppConfiguration
|
||||
public class SpringContextTest {
|
||||
|
||||
@Test
|
||||
public void whenSpringContextIsBootstrapped_thenNoExceptions() {
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user