文档章节

Servlet 3.0 web-fragment.xml

27号
 27号
发布于 2015/07/14 08:37
字数 494
阅读 11
收藏 0

Servlet 3.0 web-fragment.xml

By Shing Wai Chan on May 07, 2009

In  JSR 315: Java Servlet 3.0 Specification, web-fragment.xml is introduced for pluggability of library jars which are packaged under WEB-INF/lib. The content of web.xml and web-fragment.xml are almost the same. One can define servlets, filters and listeners there. One can also specify metadata-complete=true in a given web-fragment.xml. In the latter case, the annotation processing of classes in that jar would be skipped. With web-fragment.xml, library jars can be self-contained and provide web related metadata information.

The basic differences of web.xml and web-fragment.xml are summarized in the following table:

  web.xml web-fragment.xml
Location WEB-INF of the war file META-INF directory of JAR file inside WAR file's WEB-INF/lib
Ordering related element <absolute-ordering> <ordering>

Ordering of web fragments

If there are more than one web-fragment jars, then one may like to specify the order of processing web-fragment.xml and annotations. This is important. For instance, filters will be executed in the order specified in web.xml. Similary for listeners. In Servlet 3.0, <absolute-ordering> is introduced in web.xml and <ordering> is introduced in web-fragment.xml. The ordering of web-fragments is specified in the following priority:
  • from <absolute-ordering> in web.xml if it exists
  • from <ordering> for each web-fragment.xml if it exists
  • otherwise unspecified

absolute-ordering in web.xml

The <absolute-ordering> in web.xml provides a way to specify the ordering of loading web-fragment.xml and annotation processing of web fragment. For instance,
<web-app> 
    ... 
    <absolute-ordering> 
        <name>A</name> 
         <others/> 
        <name>B</name> 
    <absolute-ordering> 
</web-app>
In the above example, the web fragment A would be processed first and web fragment B would be processed last. Note the name A and B are specified in name element of web-fragment.xml (see examples below).

ordering in web-fragment.xml

If there is no <absolute-ordering> in web.xml, then one would look at <ordering> in web-fragment.xml. The details are described in section 8.2.3 of Servlet 3.0 spec. Let us look at some examples.
  • There is only one jar having <ordering> in web-fragment.xml.
    <web-fragment> 
        <name>A</name> 
        ... 
        <ordering> 
            <before> 
                <others/> 
            </before> 
        </ordering> 
    </web-fragment>
    In this case, web-fragment A would be processed first.
  • There are two jars having <ordering> in web-fragment.xml, namely 
    web-fragment A:
    <web-fragment> 
        <name>A</name> 
        ... 
        <ordering> 
            <before> 
                <others/> 
            </before> 
        </ordering> 
    </web-fragment>

    web-fragment B:

    <web-fragment> 
        <name>B</name> 
        ... 
        <ordering> 
            <before> 
                <others/> 
            </before> 
        </ordering> 
    </web-fragment>
    Both web-fragment A and B would like to be processed first. In this case, one only guarantee that both A and B are processed before other web-fragments. But the ordering of A and B are not determined, that is arbitrary in this case.
  • There are two jars having <ordering> in web-fragment.xml, namely 
    web-fragment A:
    <web-fragment> 
        <name>A</name> 
        ... 
        <ordering> 
            <before> 
                <others/> 
            </before> 
        </ordering> 
    </web-fragment>

    web-fragment B:

    <web-fragment> 
        <name>B</name> 
        ... 
        <ordering> 
            <after> 
                <name>A</name> 
            </after> 
            <before> 
                <others/> 
            </before> 
        </ordering> 
    </web-fragment>
    In this case, A would be processed first, then followed by B, and then other web-fragments.
If one would like to have a deterministic ordering, then I would recommend to use absolute-ordering in web.xml.

本文转载自:https://blogs.oracle.com/swchan/entry/servlet_3_0_web_fragment

27号
粉丝 31
博文 43
码字总数 7052
作品 0
长春
技术主管
私信 提问
Servlet 3.0 特性详解

Servlet 是 Java EE 规范体系的重要组成部分,也是 Java 开发人员必须具备的基础技能,本文主要介绍了 Servlet 3.0 引入的若干重要新特性,包括异步处理、新增的注解支持、可插性支持等等,为...

那位先生
2015/06/12
0
0
Servlet 3.0 新特性详解

简介: Servlet 是 Java EE 规范体系的重要组成部分,也是 Java 开发人员必须具备的基础技能,Servlet 3.0 是 Servlet 规范的最新版本。本文主要介绍了 Servlet 3.0 引入的若干重要新特性,包...

红薯
2010/04/23
1K
3
Servlet 3.0 新特性

Servlet 3.0 作为 Java EE 6 规范体系中一员,随着 Java EE 6 规范一起发布。该版本在前一版本(Servlet 2.5)的基础上提供了若干新特性用于简化 Web 应用的开发和部署。其中有几项特性的引入...

壹炮倾城
2013/06/13
0
1
Servlet 3.0 中的三种定义 Servlet 的方式

今晚没事,对 Servlet 3.0 进行一些简单的探索,有点意思。 在新发布的 Servlet 3.0 规范中,为一个 Web 应用增加一个 Servlet (过滤器、监听器与 Servlet 三者的配置都是等价的)配置有如下...

红薯
2010/07/21
495
5
Servlet 3.0 正式草案发布

In my December 2008 blog, I strongly criticised the Servlet 3.0 JSR-315 process and the resulting Public Review Draft, describing it as a: "poor document and the product of a di......

红薯
2009/05/22
2.2K
1

没有更多内容

加载失败,请刷新页面

加载更多

利用mybatis generator生成实体类、Mapper接口以及对应的XML文件

项目中通常会遇到数据的持久化,如果是采用mybatis的orm,就会涉及到生成xml的问题,刚好mybatis官网提供了这么个插件MyBatis Generator,效果简直是棒呆。 1. 首先需要在build.gradle文件中...

啊哈关关
今天
2
0
SpringSocial相关的知识点

使用SprigSocial开发第三方登录 核心类 ServiceProvider(AbstractOauth2ServiceProvider):主要负责实现server提供商(例如QQ,微信等共有的东西),默认实现类是AbstractOauth2ServiceProvider...

chendom
今天
3
0
Java并发之AQS详解

一、概述   谈到并发,不得不谈ReentrantLock;而谈到ReentrantLock,不得不谈AbstractQueuedSynchronizer(AQS)!   类如其名,抽象的队列式的同步器,AQS定义了一套多线程访问共享资源...

群星纪元
昨天
4
0
Fabric-sdk-java最新教程

Fabric Java SDK是Fabric区块链官方提供的用于Java应用开发的SDK,全称为Fabric-sdk-java,网上可用资料不多,本文列出了精心整理的针对Fabric Java SDK的最新精选教程。 如果希望快速掌握F...

汇智网教程
昨天
3
0
react 子组件监听props 变化

componentWillReceiveProps //已经被废弃 getDerivedStateFromProps// 推荐使用//如果条件不存在必须要返回null static getDerivedStateFromProps(props, current_stat...

一箭落旄头
昨天
3
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部