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.  
  24. } 

这个类我们只需要实现一个方法,就是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,如需转载请自行联系原作者

目录
相关文章
|
监控 Java API
Spring Boot 3.2 结合 Spring Cloud 微服务架构实操指南 现代分布式应用系统构建实战教程
Spring Boot 3.2 + Spring Cloud 2023.0 微服务架构实践摘要 本文基于Spring Boot 3.2.5和Spring Cloud 2023.0.1最新稳定版本,演示现代微服务架构的构建过程。主要内容包括: 技术栈选择:采用Spring Cloud Netflix Eureka 4.1.0作为服务注册中心,Resilience4j 2.1.0替代Hystrix实现熔断机制,配合OpenFeign和Gateway等组件。 核心实操步骤: 搭建Eureka注册中心服务 构建商品
1653 3
|
JavaScript 前端开发 Java
垃圾分类管理系统基于 Spring Boot Vue 3 微服务架构实操指南
本文介绍了基于Java技术的垃圾分类管理系统开发方案与实施案例。系统采用前后端分离架构,后端使用Spring Boot框架搭配MySQL数据库,前端可选择Vue.js或Java Swing实现。核心功能模块包括垃圾分类查询、科普教育、回收预约等。文中提供了两个典型应用案例:彭湖花园小区使用的Swing桌面系统和基于Spring Boot+Vue的城市管理系统,分别满足不同场景需求。最新技术方案升级为微服务架构,整合Spring Cloud、Redis、Elasticsearch等技术,并采用Docker容器
784 1
|
监控 Cloud Native Java
Spring Boot 3.x 微服务架构实战指南
🌟蒋星熠Jaxonic,技术宇宙中的星际旅人。深耕Spring Boot 3.x与微服务架构,探索云原生、性能优化与高可用系统设计。以代码为笔,在二进制星河中谱写极客诗篇。关注我,共赴技术星辰大海!(238字)
1607 2
Spring Boot 3.x 微服务架构实战指南
|
Java 数据库 数据安全/隐私保护
Spring Boot四层架构深度解析
本文详解Spring Boot四层架构(Controller-Service-DAO-Database)的核心思想与实战应用,涵盖职责划分、代码结构、依赖注入、事务管理及常见问题解决方案,助力构建高内聚、低耦合的企业级应用。
2058 1
|
Kubernetes Java 微服务
Spring Cloud 微服务架构技术解析与实践指南
本文档全面介绍 Spring Cloud 微服务架构的核心组件、设计理念和实现方案。作为构建分布式系统的综合工具箱,Spring Cloud 为微服务架构提供了服务发现、配置管理、负载均衡、熔断器等关键功能的标准化实现。本文将深入探讨其核心组件的工作原理、集成方式以及在实际项目中的最佳实践,帮助开发者构建高可用、可扩展的分布式系统。
1023 0
|
存储 Java 数据库连接
简单学Spring Boot | 博客项目的三层架构重构
本案例通过采用三层架构(数据访问层、业务逻辑层、表现层)重构项目,解决了集中式开发导致的代码臃肿问题。各层职责清晰,结合依赖注入实现解耦,提升了系统的可维护性、可测试性和可扩展性,为后续接入真实数据库奠定基础。
979 0
|
Java 开发者 Spring
Spring框架 - 深度揭秘Spring框架的基础架构与工作原理
所以,当你进入这个Spring的世界,看似一片混乱,但细看之下,你会发现这里有个牢固的结构支撑,一切皆有可能。不论你要建设的是一座宏大的城堡,还是个小巧的花园,只要你的工具箱里有Spring,你就能轻松搞定。
631 9

推荐镜像

更多