MESSL(maven + extjs + spring portlet mvc + spring web flow + liferay )整合架构 4

简介:

 上篇文章讲到了我们定义portlet应用级别的spring 配置文件为/WEB-INF/config/envprovisioning-config.xml ,下面我们来看下这个spring配置文件内容:

 

 
 
  1. <?xml version="1.0" encoding="UTF-8"?> 
  2. <beans xmlns="http://www.springframework.org/schema/beans" 
  3.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  4.        xmlns:webflow="http://www.springframework.org/schema/webflow-config" 
  5.        xsi:schemaLocation=" 
  6.            http://www.springframework.org/schema/beans 
  7.            http://www.springframework.org/schema/beans/spring-beans.xsd 
  8.            http://www.springframework.org/schema/webflow-config 
  9.            http://www.springframework.org/schema/webflow-config/spring-webflow-config.xsd"> 
  10.  
  11.     <!-- Maps portlet modes to handlers -->  
  12.     <bean id="portletModeHandlerMapping" class="org.springframework.web.portlet.handler.PortletModeHandlerMapping"> 
  13.         <property name="portletModeMap"> 
  14.             <map> 
  15.                 <entry key="view"> 
  16.                     <bean class="com.walmart.platform.envprovisioning.handlers.EnvProvisionFlowHandler" /> 
  17.                 </entry> 
  18.             </map> 
  19.         </property> 
  20.         <property name="interceptors">   
  21.             <list>   
  22.                 <ref bean="envprovisionhandlerinterceptor"/> 
  23.             </list>   
  24.         </property> 
  25.     </bean> 
  26.     <!-- add interceptor to get user and privilege --> 
  27.     <bean id="envprovisionhandlerinterceptor" class="com.walmart.platform.envprovisioning.interceptors.EnvProvisionHandlerInterceptor"/> 
  28.  
  29.     <!-- Maps logical view names selected by the url filename controller to .jsp view templates within the /WEB-INF directory -->    
  30.     <bean id="internalJspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
  31.         <property name="prefix" value="/WEB-INF/" /> 
  32.         <property name="suffix" value=".jsp" /> 
  33.     </bean> 
  34.      
  35.     <!-- Enables FlowHandlers --> 
  36.     <bean class="org.springframework.webflow.mvc.portlet.FlowHandlerAdapter"> 
  37.         <property name="flowExecutor" ref="flowExecutor"/> 
  38.     </bean> 
  39.  
  40.     <!-- Executes flows: the central entry point into the Spring Web Flow system --> 
  41.     <webflow:flow-executor id="flowExecutor" /> 
  42.      
  43.     <!-- The registry of executable flow definitions --> 
  44.     <webflow:flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices"> 
  45.         <webflow:flow-location path="/WEB-INF/flows/envprovision/envprovision.xml" /> 
  46.     </webflow:flow-registry>     
  47.  
  48.     <!-- Plugs in Spring's JSR-303 validator adapter --> 
  49.     <webflow:flow-builder-services id="flowBuilderServices" development="true" validator="validator" /> 
  50.          
  51.     <!-- Bootstraps JSR-303 validation and exposes it through Spring's Validator interface --> 
  52.     <bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"/> 
  53.  
  54.   
  55. </beans> 

这个文件更多的是对spring web flow进行了配置,容我细细道来:

首先在第15-17行,我们portletModeMap,对view Mode ,我们扔给了EnvProvisionFlowHandler类,这就表明,我们让在spring portlet mvc中,我们用EnvProvisionFlowHandler类充当portlet view mode的处理类。 而这个EnvProvisionFlowHandler类是从AbstractFlowHandler继承来的, 所以我们理所当然的使用了Spring WebFlow 的FlowHandler来充当处理器:

 
 
  1. /** 
  2.  * this class is the flowHandler 
  3.  * When application deployed to container ,the container will read the envprovisioning-config.xml 
  4.  * then it will get the instance for this flowHandler ,and the getFlowId() method will identify which flow it will 
  5.  * enter into. 
  6.  *  
  7.  *@author cwang58 
  8.  *@created date: Feb 18, 2013 
  9.  */ 
  10. public class EnvProvisionFlowHandler extends AbstractFlowHandler { 
  11.  
  12.     /** 
  13.      * the flowId which identifies the flow which will be handled by this flowHandler 
  14.      * since here it returns envprovision ,so it will go to the flow which is describled by flow 
  15.      * definition file "envprovision.xml" 
  16.      */ 
  17.     public String getFlowId() { 
  18.     return "envprovision"
  19.     } 
  20.  
  21.      
  22.  
  23.  

这个类我们只需要实现一个方法,就是getFlowId(),他用来表示,我们用什么web flow来充当view 模式的处理器, 在这里,返回的是envprovision,所以我们用这个流来充当view模式处理器。

 

既然得到了flowId之后,我们就去找对应的 web flow.首先必须明白,flow的执行者是由FlowHandlerAdaptor来完成的,所以我们在36-38行,我们定义了一个属性叫flowExecutor来专门用于执行flow.

而flowExecutor会专门使用一个flowRegistry Bean来执行定义在/WEB-INF/flows 下的基于XML的流跳转定义文件,所以我们又在44-46行中显式的给出了流定义XML文件,因为(Convention over Configuration),默认的流定义文件的文件名就是flowId,所以我们很容易找到了前文中返回的envprovision的流Id就对应这里的envprovision.xml文件,所以当portlet view 模式时,就会把控制权交给Spring Web Flow,然后用envprovision.xml中定义的流跳转逻辑来处理view 模式,就这么简单。

 

下篇文章我们来探讨这个流控制文件。





本文转自 charles_wang888 51CTO博客,原文链接:http://blog.51cto.com/supercharles888/1138849,如需转载请自行联系原作者

目录
相关文章
|
29天前
|
缓存 前端开发 Java
Spring MVC 面试题及答案整理,最新面试题
Spring MVC 面试题及答案整理,最新面试题
85 0
|
29天前
ssm(Spring+Spring mvc+mybatis)——updateDept.jsp
ssm(Spring+Spring mvc+mybatis)——updateDept.jsp
10 0
|
29天前
ssm(Spring+Spring mvc+mybatis)——showDept.jsp
ssm(Spring+Spring mvc+mybatis)——showDept.jsp
9 0
|
28天前
|
SQL JavaScript Java
springboot+springm vc+mybatis实现增删改查案例!
springboot+springm vc+mybatis实现增删改查案例!
23 0
|
28天前
|
SQL Java 数据库连接
挺详细的spring+springmvc+mybatis配置整合|含源代码
挺详细的spring+springmvc+mybatis配置整合|含源代码
34 1
|
1天前
|
负载均衡 Java 开发者
细解微服务架构实践:如何使用Spring Cloud进行Java微服务治理
【4月更文挑战第17天】Spring Cloud是Java微服务治理的首选框架,整合了Eureka(服务发现)、Ribbon(客户端负载均衡)、Hystrix(熔断器)、Zuul(API网关)和Config Server(配置中心)。通过Eureka实现服务注册与发现,Ribbon提供负载均衡,Hystrix实现熔断保护,Zuul作为API网关,Config Server集中管理配置。理解并运用Spring Cloud进行微服务治理是现代Java开发者的关键技能。
|
6天前
|
数据采集 前端开发 Java
数据塑造:Spring MVC中@ModelAttribute的高级数据预处理技巧
数据塑造:Spring MVC中@ModelAttribute的高级数据预处理技巧
19 3
|
6天前
|
存储 前端开发 Java
会话锦囊:揭示Spring MVC如何巧妙使用@SessionAttributes
会话锦囊:揭示Spring MVC如何巧妙使用@SessionAttributes
12 1
|
6天前
|
前端开发 Java Spring
数据之桥:深入Spring MVC中传递数据给视图的实用指南
数据之桥:深入Spring MVC中传递数据给视图的实用指南
20 3
|
15天前
|
前端开发 安全 Java
使用Java Web框架:Spring MVC的全面指南
【4月更文挑战第3天】Spring MVC是Spring框架的一部分,用于构建高效、模块化的Web应用。它基于MVC模式,支持多种视图技术。核心概念包括DispatcherServlet(前端控制器)、HandlerMapping(请求映射)、Controller(处理请求)、ViewResolver(视图解析)和ModelAndView(模型和视图容器)。开发流程涉及配置DispatcherServlet、定义Controller、创建View、处理数据、绑定模型和异常处理。
使用Java Web框架:Spring MVC的全面指南