OFBiz使用了大量的配置文件,整个过程有点复杂。这里将配置过程大略整理了一下,方便后面查阅。
第一层:org.ofbiz.base.start.Start启动类。该类载入org/ofbiz/base/start/start.properties定义的载入类loader,可以定义多个载入类,最典型的载入类是org.ofbiz.base.container.ContainerLoader。
# --- Location (relative to ofbiz.home) for (normal) container configuration ofbiz.container.config=framework/base/config/ofbiz-containers.xml # --- StartupLoader implementations to load (in order) ofbiz.start.loader1=org.ofbiz.base.container.ContainerLoader
第二层:org.ofbiz.base.container.ContainerLoader载入类。该类载入framework/base/config/ofbiz-containers.xml定义的容器,可以定义多个容器,最典型的容器是org.ofbiz.base.container.ComponentContainer。ofbiz-containers.xml的位置由start.properties的ofbiz.container.config指定。
<?xml version="1.0" encoding="UTF-8"?> <ofbiz-containers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/ofbiz-containers.xsd"> <!-- load the ofbiz component container (always first) --> <container name="component-container" class="org.ofbiz.base.container.ComponentContainer"/> <!-- load the cached classloader container (always second) --> <container name="classloader-container" class="org.ofbiz.base.container.ClassLoaderContainer"/> <!-- load the naming (JNDI) server --> <container name="naming-container" class="org.ofbiz.base.container.NamingServiceContainer"> <property name="host" value="0.0.0.0"/> <property name="port" value="1099"/> </container> ... ... </ofbiz-containers>
第三层:org.ofbiz.base.container.ComponentContainer容器类。该类载入framework/base/config/component-load.xml定义的组件位置。component-load.xml的位置可以由ofbiz-containers.xml的loader-config属性指定。
<?xml version="1.0" encoding="UTF-8"?> <component-loader xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/component-loader.xsd"> <load-components parent-directory="framework"/> <load-components parent-directory="themes"/> <load-components parent-directory="applications"/> <load-components parent-directory="specialpurpose"/> <load-components parent-directory="hot-deploy"/> </component-loader>
第四层:org.ofbiz.base.component.ComponentConfig类。该类载入具体的组件ofbiz-component.xml。
<?xml version="1.0" encoding="UTF-8"?> <ofbiz-component name="base" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/ofbiz-component.xsd"> <resource-loader name="main" type="component"/> <classpath type="jar" location="build/lib/*"/> <classpath type="dir" location="config"/> <classpath type="jar" location="lib/*"/> <test-suite loader="main" location="testdef/basetests.xml"/> </ofbiz-component>