如何通过 Web "inform"我的 Web 应用程序.xml我有一个关于 Spring Webflow 的配置文件?



我正在用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 webflow创建了配置,并用名称"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>

在上面的代码中,我声明了我想为我的网络流遵循的文件夹/url模式

/WEB-INF/flows/*-flow/*-flow.xml

问题是,我如何设法通知我的 Web 应用程序存在有关spring webflow的配置?

我查找了很多示例和教程,但由于一些有趣的原因,没有人解释

a(每个配置文件应该放在哪个文件夹中,也不是

b(配置文件应该具有什么名称,以便从框架中识别Spring Webflow

如果您知道如何"通知"我的 Web 应用程序有关Spring Webflow的信息,请告诉我。

提前谢谢你。

将 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

最新更新