我正在用Java 8编写Web应用程序。我使用Maven并在项目中包含了有关Spring Webflow的依赖项:
<dependency>
<groupId>org.springframework.webflow</groupId>
<artifactId>spring-webflow</artifactId>
<version>2.4.5.RELEASE</version>
</dependency>
我使用基于表单的身份验证,我的web.xml如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="PROJECT" version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
xmlns:h="http://java.sun.com/jsf/html" xmlns:p="http://primefaces.org/ui"
xmlns:pt="http://xmlns.jcp.org/jsf/passthrough" xmlns:o="http://omnifaces.org/ui"
xmlns:of="http://omnifaces.org/functions">
<display-name>PROJECT</display-name>
/*
* Somewhere here should I insert something in order to have
* my web application informed, that there is a spring-webflow-config.xml
* configuration file. How do I do this?
*/
<welcome-file-list>
<welcome-file>WEB-INF/firstPage.xhtml</welcome-file>
</welcome-file-list>
<security-constraint>
<display-name>Constraint</display-name>
<web-resource-collection>
<web-resource-name></web-resource-name>
<description />
<url-pattern>/flows/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<description />
<role-name>ADMIN</role-name>
<role-name>USER</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>FORM</auth-method>
<realm-name>file</realm-name>
<form-login-config>
<form-login-page>WEB-INF/login.xhtml</form-login-page>
<form-error-page>WEB-INF/error.xhtml</form-error-page>
</form-login-config>
</login-config>
<security-role>
<description>Administration</description>
<role-name>ADMIN</role-name>
</security-role>
<security-role>
<description>User</description>
<role-name>USER</role-name>
</security-role>
</web-app>
我还创建了spring webflows的配置,我把它命名为“WEB-INF \ config \ spring-webflow-config.xml”,它看起来像这样:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:webflow="http://www.springframework.org/schema/webflow-config"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/webflow-config
http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.0.xsd">
<mvc:annotation-driven />
<!-- Webflow Configuration -->
<webflow:flow-executor id="flowExecutor" />
<webflow:flow-registry id="flowRegistry">
<webflow:flow-location-pattern value="/WEB-INF/flows/*-flow/*-flow.xml" />
</webflow:flow-registry>
<bean id="flowMappings"
class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping">
<property name="order" value="0" />
<property name="flowRegistry" ref="flowRegistry" />
</bean>
<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerAdapter">
<property name="flowExecutor" ref="flowExecutor" />
</bean>
在上面的代码中,我声明了我想要为我的webflows关注的文件夹/ url-pattern
/WEB-INF/flows/*-flow/*-flow.xml
问题是,如何通知我的网络应用程序有spring webflow
的配置?
我查了很多例子和教程,但由于一些有趣的原因,没有人解释
a)每个配置文件应放在哪个文件夹中,
b)配置文件应具有的名称,以便从Spring Webflow
框架中识别。
如果您知道如何“通知”我的网络应用程序Spring Webflow
,请告知我们。
提前谢谢。
答案 0 :(得分:0)
放置Webflow配置文件的位置并不特别重要,您只需告诉Spring DispatcherServlet:
<servlet>
<servlet-name>Spring MVC Dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/config/spring-webflow-config.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Spring MVC Dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
它可能并不明显,但它是Spring MVC设置,由WebFlow官方文档的这一部分描述:http://docs.spring.io/spring-webflow/docs/current/reference/html/spring-mvc.html#spring-mvc-config-web.xml