在ofbiz中,有一个非常重要的配置文件ofbiz-component.xml,这个文件告诉ofbiz需要加载那些容器和类,在start.properties中有如下定义
//ofbiz容器加载类,用来加载其他容器,ofbiz
ofbiz.start.loader1=org.ofbiz.base.container.ContainerLoader
//ofbiz加载的组件级别
ofbiz.start.loader1.loaders=main,rmi
ContainerLoader根据framework\base\config\ofbiz-containers.xml中定义的容器按顺序启动容器
//此处的loaders="main,rmi,pos,install",包含start.properties中的加载级别,该容器是符合要求的启动容器,事实上生产模式上只启动这一个容器
<container name="component-container" loaders="main,rmi,pos,install" class="org.ofbiz.base.container.ComponentContainer"/>
<container name="component-container-test" loaders="test" class="org.ofbiz.base.container.ComponentContainer">
<property name="ofbiz.instrumenterClassName" value="org.ofbiz.base.config.CoberturaInstrumenter"/>
<property name="ofbiz.instrumenterFile" value="runtime/logs/cobertura-components.dat"/>
</container>
<container name="component-container-limited" loaders="limited" class="org.ofbiz.base.container.ComponentContainer">
<property name="update-classpath" value="false"/>
</container>
<container name="component-container" loaders="testlist" class="org.ofbiz.base.container.JustLoadComponentsContainer"/>
component-container是组件加载容器,根据framework\base\config\component-load.xml中定义的组件目录查找component-load.xml文件然后加载这些文件
这些配置都存放在org.ofbiz.base.component.ComponentConfig中
// this is not a UtilCache because reloading may cause problems
//普通组件配置文件存放位置
protected static Map<String, ComponentConfig> componentConfigs = FastMap.newInstance();
//web组件配置文件存放位置
protected static Map<String, List<WebappInfo>> serverWebApps = FastMap.newInstance();
下边看一个最基本的component-load.xml文件结构
<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"/> <!-- load the cached classloader container (always second) --> <container name="classloader-container" loaders="main,rmi,pos,install,test" class="org.ofbiz.base.container.ClassLoaderContainer"/> <!-- load the naming (JNDI) server --> <container name="naming-container" loaders="rmi" class="org.ofbiz.base.container.NamingServiceContainer"> <property name="host" value="0.0.0.0"/> <property name="port" value="1099"/> </container> <!-- load BeanShell remote telnet server --> <!-- Commented out by default for security reasons --> <!-- the port below and port-1 will be opened by Beanshell --> <!--container name="beanshell-container" class="org.ofbiz.base.container.BeanShellContainer"> <property name="telnet-port" value="9990"/> <property name="app-name" value="OFBiz"/> </container--> </ofbiz-component>
这些配置文件都会被加载到ComponentCofig类中,在这个类中有相应的字段用来存放这些配置
protected String globalName = null;
protected String rootLocation = null;
protected String componentName = null;
protected boolean enabled = true;
protected Map<String, ResourceLoaderInfo> resourceLoaderInfos = FastMap.newInstance();
protected List<ClasspathInfo> classpathInfos = FastList.newInstance();
protected List<EntityResourceInfo> entityResourceInfos = FastList.newInstance();
protected List<ServiceResourceInfo> serviceResourceInfos = FastList.newInstance();
protected List<TestSuiteInfo> testSuiteInfos = FastList.newInstance();
protected List<KeystoreInfo> keystoreInfos = FastList.newInstance();
protected List<WebappInfo> webappInfos = FastList.newInstance();
protected List<ContainerConfig.Container> containers = FastList.newInstance();
最后通过Map将这些配置保存,提供给下一步使用
总结:
以上流程可以通过下图进行展示
个人见解,如有错误,请不吝赐教
转载于:https://blog.51cto.com/canghailongteng/1663030