JBoss 启动文件 jboss-6.1.0.Final/server/default/conf/bootstrap.xml 是加载服务内容的入口。
在 JBoss 初始化操作的最后一个步骤中 , AbstractJBossASServerBase setupBootstrapDescriptorsFromBootstrapUrl()方法中,完成了对 bootstrap.xml的解析。
过程如下:
protected void setupBootstrapDescriptorsFromBootstrapUrl() {
final URL bootstrapUrl = this.getConfiguration().getBootstrapUrl();
// bootstrapUrl = E:/jboss-6.1.0.Final/server/default/conf/bootstrap.xml
if (bootstrapUrl == null) {
throw new IllegalStateException("Bootstrap URL should have been initialized");
}
final BootstrapMetaData bmd = BootstrapParser.parse(bootstrapUrl);
final List<String> urlStrings = bmd.getBootstrapURLs();
...
}
public class BootstrapParser{ public static BootstrapMetaData parse(URL url) { if (url == null) throw new IllegalArgumentException("Null url"); UnmarshallerFactory factory = UnmarshallerFactory.newInstance(); Unmarshaller unmarshaller = factory.newUnmarshaller(); try { BootstrapMetaData result = (BootstrapMetaData) unmarshaller.unmarshal(url.toString(), new BootstrapSchemaBinding()); if (result == null) throw new IllegalStateException("The bootsrap xml " + url + " is not well formed"); return result; } catch (Exception e) { throw new RuntimeException("Error unmarshalling " + url, e); } }}
public static BootstrapMetaData parse(URL url){ if (url == null) throw new IllegalArgumentException("Null url"); UnmarshallerFactory factory = UnmarshallerFactory.newInstance(); Unmarshaller unmarshaller = factory.newUnmarshaller(); try{ BootstrapMetaData result = (BootstrapMetaData) unmarshaller.unmarshal(url.toString(), new BootstrapSchemaBinding()); if (result == null) throw new IllegalStateException("The bootsrap xml " + url + " is not well formed"); return result; } catch (Exception e) { throw new RuntimeException("Error unmarshalling " + url, e); } }
class BootstrapSchemaBinding extends SchemaBinding{ public static final String NAMESPACE = "urn:jboss:bootstrap:1.0"; public BootstrapSchemaBinding(){ TypeBinding stringType = getType(SimpleTypeBindings.typeQName(String.class)); setNamespaces(Collections.singleton(NAMESPACE)); setIgnoreLowLine(true); setIgnoreUnresolvedFieldOrClass(false); setReplacePropertyRefs(true); setStrictSchema(true); TypeBinding bootstrapType = new TypeBinding(new QName(NAMESPACE, "bootstrapType")); bootstrapType.setSimple(false); AllBinding bootstrapModel = new AllBinding(this); ParticleBinding bootstrapParticle = new ParticleBinding(bootstrapModel, 1, 1, false); bootstrapType.setParticle(bootstrapParticle); ClassMetaData bootstrapClassMetaData = new ClassMetaData(); bootstrapClassMetaData.setImpl(BootstrapMetaData.class.getName()); bootstrapType.setClassMetaData(bootstrapClassMetaData); ElementBinding urlElement = new ElementBinding(this, new QName(NAMESPACE, "url"), stringType); ParticleBinding urlParticle = new ParticleBinding(urlElement, 0, 1, true); bootstrapModel.addParticle(urlParticle); bootstrapType.pushInterceptor(urlElement.getQName(), new DefaultElementInterceptor() { public void add(Object parent, Object child, QName name) { BootstrapMetaData bootstrap = (BootstrapMetaData) parent; String url = (String) child; List<String> bootstrapURLs = bootstrap.getBootstrapURLs(); if (bootstrapURLs == null) { bootstrapURLs = new ArrayList<String>(); bootstrap.setBootstrapURLs(bootstrapURLs); } bootstrapURLs.add(url); } }); addElement(new ElementBinding(this, new QName(NAMESPACE, "bootstrap"), bootstrapType)); }}
解析之后,将bootstrap.xml中的内容保存到 server.getConfiguration() 对象中。
bootstrap.xml文件内容
<?xml version="1.0" encoding="UTF-8"?><!-- The list of URLs for mc beans to load during bootstrap. $Id: bootstrap.xml 106395 2010-07-02 02:16:59Z mmoyses $--><bootstrap xmlns="urn:jboss:bootstrap:1.0"> <url>bootstrap/classloader.xml</url> <url>bootstrap/stdio.xml</url> <url>bootstrap/kernel.xml</url> <url>bootstrap/aop.xml</url> <url>bootstrap/jmx.xml</url> <url>bootstrap/deployers.xml</url> <url>bootstrap/profile.xml</url> <url>bootstrap/security.xml</url></bootstrap>
与bootstrap.xml对应的解析类为 BootstrapMetaData;
解析完成后,下一步对这几个部分进行分别解析和加载。
确切的说,bootstrap中包含的 8 个配置文件,就是 微容器 Microcontainer 。
JBoss 服务初始化完成之后,服务的配置信息如下:
=======================
Server Configuration:
JBOSS_HOME URL: file:/E:/jboss-6.1.0.Final/
Bootstrap: $JBOSS_HOME\server/default/conf/bootstrap.xml
Common Base: $JBOSS_HOME\common/
Common Library: $JBOSS_HOME\common/lib/
Server Name: default
Server Base: $JBOSS_HOME\server/
Server Library: $JBOSS_HOME\server/default/lib/
Server Config: $JBOSS_HOME\server/default/conf/
Server Home: $JBOSS_HOME\server/default/
Server Data: $JBOSS_HOME\server/default/data/
Server Log: $JBOSS_HOME\server/default/log/
Server Temp: $JBOSS_HOME\server/default/tmp/