(Portal 开发读书笔记)Portlet中的Spring Web Application Context

简介:

 用一句话来说就是:

在Spring Portlet MVC 框架中,

每个Portlet都有一个相关的WebApplicationContext, 整个Portlet Application也有一个大的WebApplicationContext

 

对于Portlet级别的WebApplicationContext,

(1)它的配置文件名称必须是<portlet_name>-portlet.xml

(2)这个portlet_name 必须和portlet.xml中相应portlet的名称对应。

(3)这个配置文件必须放在 WEB-INF 目录下(默认),否则必须在portlet.xml中显式给出,通过配置 contextConfigLocation的值,这个值可以是多值,用逗号分隔

比如我要指定一个非默认位置,那么可以在portlet.xml中

 
 
  1. <portlet> 
  2. <portlet-name>helloWorld</portlet-name> 
  3. <portlet-class> 
  4. org.springframework.web.portlet.DispatcherPortlet 
  5. </portlet-class> 
  6. <init-param> 
  7. <name>contextConfigLocation</name> 
  8. <value>/WEB-INF/context/portlet/myContext.xml</value> 
  9. </init-param> 
  10. ... 
  11. </portlet> 

(4)这个配置文件仅仅对应的portlet可见,其中定义的bean也仅在对应的portlet可以访问,其他portlet不可以访问。

 

---

对于Portlet Application级别的WebApplicationContext

(1) 里面定义的bean可以被同一个应用下所有的Portlet所共享

(2) 这个配置文件中如果定义了bean的名称(id)如果和某个Portlet级别的配置文件中定义的bean的名称冲突,那么Portlet级别的会覆盖Portlet Application级别的bean.

(3) 每个Portlet级别的应用上下文会隐式的继承Portlet Application 级别的应用上下文

(4)这个文件必须默认放在WEB-INF目录下,并且默认位置是/WEB-INF/context/applicationContext.xml,可以在web.xml中指定其他位置:

 

 
 
  1. <context-param> 
  2. <param-name>contextConfigLocation</param-name> 
  3. <param-value>/WEB-INF/context/applicationContext.xml</param-value> 
  4. </context-param> 

(5)这个文件的读取者是ContextLoaderListener,所以必须在Portlet Application的web.xml中配置如下:

 
 
  1. <listener> 
  2. <listener-class> 
  3. org.springframework.web.context.ContextLoaderListener 
  4. </listener-class> 
  5. </listener> 

 

-- 总结如下

portlet.xml  平行的相当于 web.xml ,只不过前者配置了每个portlet,后者配置了整个portlet application





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

目录
相关文章
|
11月前
|
缓存 安全 Java
《深入理解Spring》过滤器(Filter)——Web请求的第一道防线
Servlet过滤器是Java Web核心组件,可在请求进入容器时进行预处理与响应后处理,适用于日志、认证、安全、跨域等全局性功能,具有比Spring拦截器更早的执行时机和更广的覆盖范围。
|
Java API 数据库
构建RESTful API已经成为现代Web开发的标准做法之一。Spring Boot框架因其简洁的配置、快速的启动特性及丰富的功能集而备受开发者青睐。
【10月更文挑战第11天】本文介绍如何使用Spring Boot构建在线图书管理系统的RESTful API。通过创建Spring Boot项目,定义`Book`实体类、`BookRepository`接口和`BookService`服务类,最后实现`BookController`控制器来处理HTTP请求,展示了从基础环境搭建到API测试的完整过程。
723 4
|
存储 安全 Java
如何在 Spring Web 应用程序中使用 @SessionScope 和 @RequestScope
Spring框架中的`@SessionScope`和`@RequestScope`注解用于管理Web应用中的状态。`@SessionScope`绑定HTTP会话生命周期,适用于用户特定数据,如购物车;`@RequestScope`限定于单个请求,适合无状态、线程安全的操作,如日志记录。合理选择作用域能提升应用性能与可维护性。
463 1
|
存储 NoSQL Java
探索Spring Boot的函数式Web应用开发
通过这种方式,开发者能以声明式和函数式的编程习惯,构建高效、易测试、并发友好的Web应用,同时也能以较小的学习曲线迅速上手,因为这些概念与Spring Framework其他部分保持一致性。在设计和编码过程中,保持代码的简洁性和高内聚性,有助于维持项目的可管理性,也便于其他开发者阅读和理解。
316 0
|
前端开发 Java API
Spring Cloud Gateway Server Web MVC报错“Unsupported transfer encoding: chunked”解决
本文解析了Spring Cloud Gateway中出现“Unsupported transfer encoding: chunked”错误的原因,指出该问题源于Feign依赖的HTTP客户端与服务端的`chunked`传输编码不兼容,并提供了具体的解决方案。通过规范Feign客户端接口的返回类型,可有效避免该异常,提升系统兼容性与稳定性。
932 0
|
网络协议 Java Shell
java spring 项目若依框架启动失败,启动不了服务提示端口8080占用escription: Web server failed to start. Port 8080 was already in use. Action: Identify and stop the process that’s listening on port 8080 or configure this application to listen on another port-优雅草卓伊凡解决方案
java spring 项目若依框架启动失败,启动不了服务提示端口8080占用escription: Web server failed to start. Port 8080 was already in use. Action: Identify and stop the process that’s listening on port 8080 or configure this application to listen on another port-优雅草卓伊凡解决方案
1238 7
|
Java 开发者 微服务
Spring Boot 入门:简化 Java Web 开发的强大工具
Spring Boot 是一个开源的 Java 基础框架,用于创建独立、生产级别的基于Spring框架的应用程序。它旨在简化Spring应用的初始搭建以及开发过程。
1231 7
Spring Boot 入门:简化 Java Web 开发的强大工具
|
前端开发 安全 Java
技术进阶:使用Spring MVC构建适应未来的响应式Web应用
【9月更文挑战第2天】随着移动设备的普及,响应式设计至关重要。Spring MVC作为强大的Java Web框架,助力开发者创建适应多屏的应用。本文推荐使用Thymeleaf整合视图,通过简洁的HTML代码提高前端灵活性;采用`@ResponseBody`与`Callable`实现异步处理,优化应用响应速度;运用`@ControllerAdvice`统一异常管理,保持代码整洁;借助Jackson简化JSON处理;利用Spring Security增强安全性;并强调测试的重要性。遵循这些实践,将大幅提升开发效率和应用质量。
317 7
|
XML Java 网络架构
使用 Spring Boot 公开 SOAP Web 服务端点:详细指南
使用 Spring Boot 公开 SOAP Web 服务端点:详细指南
2038 0