可使用 WAB 配置文件来配置 Web 应用程序捆绑软件 (WAB)。要配置 WAB,必须将
WABConfiguration 注册为 OSGi 服务。WABConfiguration 是没有方法的标记接口。WAB 的配置是由
WABConfiguration OSGi 服务注册信息使用 contextName
和 contextPath 服务属性指定。
关于此任务
WAB 使用 OSGi 捆绑软件清单头
Web-ContextPath
来指定上下文路径。要指定 WAB 具有可配置的上下文路径,
Web-ContextPath
标头值必须以
@ 字符开头,初始
@ 字符后的其余字符用作
contextName。以下示例说明具有可配置上下文路径的 WAB:
Web-ContextPath: @myWABContextPath
过程
- 使用 contextName 值 myWABContextPath 来注册 WABConfiguration 服务,以配置上下文路径。 可使用声明式服务组件。
@Component(
configurationPid = "my.wab.configuration",
configurationPolicy = ConfigurationPolicy.REQUIRE)
public class MyWABConfiguration implements WABConfiguration {
// Only used to set "contextPath" and "contextName" service
// properties from configuration admin using the pid
// my.wab.configuration
}
- metatype.xml 文件中包含的以下 XML 用于定义服务组件的配置选项。
<metatype:MetaData xmlns:metatype="http://www.osgi.org/xmlns/metatype/v1.1.0"
xmlns:ibm="http://www.ibm.com/xmlns/appservers/osgi/metatype/v1.0.0"
localization="OSGI-INF/l10n/metatype">
<OCD description="My WAB Configuration" name="My WAB Configuration"
id="my.wab.configuration" ibm:alias="myWAB">
<AD name="Context Path" description="The Context Path"
id="contextPath" required="true" type="String" default="/default/path" />
<AD name="internal" description="internal"
id="contextName" ibm:final="true" type="String" default="myWABContextPath" />
</OCD>
<Designate pid="my.wab.configuration">
<Object ocdref="my.wab.configuration"/>
</Designate>
</metatype:MetaData>
此元类型指定 contextName 和 contextPath
属性的缺省值。如果未指定其他配置,那么将使用缺省值来配置 WAB 上下文路径。
注: 标识为
contextName 的
<AD> 元素将
internal 用作名称,并包含
ibm:final。这允许为服务组件指定缺省值,但不允许覆盖
server.xml 配置中的缺省值。然后,可使用以下
server.xml 配置元素来配置 WAB 上下文路径:
<usr_myWAB contextPath="/myWab/path"/>
如果将包含 WABCconfiguration 组件的捆绑软件安装为 usr
功能部件,那么必须使用 usr_ 前缀。如果随某个产品扩展一起安装该捆绑软件,那么前缀是后跟
_ 字符的产品名称。有关产品扩展的更多信息,请参阅Liberty:产品扩展。