寻找文件的方式最后是通过ComponentConfig.java的getURL方法来解析的
public URL getURL(String resourceLoaderName, String location) throws ComponentException {
ResourceLoaderInfo resourceLoaderInfo = resourceLoaderInfos.get(resourceLoaderName);
if (resourceLoaderInfo == null) {
throw new ComponentException("Could not find resource-loader named: " + resourceLoaderName);
}
if ("component".equals(resourceLoaderInfo.type) || "file".equals(resourceLoaderInfo.type)) {
//如果是<resource-loader name="main" type="component" />
String fullLocation = getFullLocation(resourceLoaderName, location);
URL fileUrl = UtilURL.fromFilename(fullLocation);
if (fileUrl == null) {
throw new ComponentException("File Resource not found: " + fullLocation);
}
return fileUrl;
} else if ("classpath".equals(resourceLoaderInfo.type)) {
String fullLocation = getFullLocation(resourceLoaderName, location);
URL url = UtilURL.fromResource(fullLocation);
if (url == null) {
throw new ComponentException("Classpath Resource not found: " + fullLocation);
}
return url;
} else if ("url".equals(resourceLoaderInfo.type)) {
String fullLocation = getFullLocation(resourceLoaderName, location);
URL url = null;
try {
url = FlexibleLocation.resolveLocation(location);
} catch (java.net.MalformedURLException e) {
throw new ComponentException("Error with malformed URL while trying to load URL resource at location [" + fullLocation + "]", e);
}
if (url == null) {
throw new ComponentException("URL Resource not found: " + fullLocation);
}
return url;
} else {
throw new ComponentException("The resource-loader type is not recognized: " + resourceLoaderInfo.type);
}
}
其中主要是看
就是用getFullLocation(resourceLoaderName, location);方法
它做的事是判断如果类型是component,就进行rootLocation+location。而rootLocation就是组建所在路径,而location就是我们的entity-resource或者service-resource等等设置的location。
另外这个方法还有几个操作,判断是否要使用prependEnv,如果使用,会添加上prependEnv
if (UtilValidate.isNotEmpty(resourceLoaderInfo.prependEnv)) {
String propValue = System.getProperty(resourceLoaderInfo.prependEnv);
if (propValue == null) {
String errMsg = "The Java environment (-Dxxx=yyy) variable with name " + resourceLoaderInfo.prependEnv + " is not set, cannot load resource.";
Debug.logError(errMsg, module);
throw new IllegalArgumentException(errMsg);
}
buf.append(propValue);
}
//判断是否要添加prefix
if (UtilValidate.isNotEmpty(resourceLoaderInfo.prefix)) {
buf.append(resourceLoaderInfo.prefix);
}
由此可以得出,resource-loader元素的完整配置是
<resource-loader name="main" type="component" prepend-env="" prefix=""/>
分享到:
相关推荐
`web.xml`是标准的Servlet配置文件,而`controller.xml`则用于处理Ofbiz中的请求。 `web.xml`文件通常会包含关于Web应用程序的基本信息,如显示名称和描述,以及应用程序上下文参数。例如: ```xml <web-app> ...
每个组件目录下的`ofbiz-component.xml`文件描述了组件的相关属性,包括entity-resource的定义、测试用例的位置、类路径设置以及服务资源等。对于应用程序(APP),组件还能定义其虚拟路径,使得在系统中可以方便地...
2. `ofbiz-component.xml`文件的作用是告诉OFBiz框架如何定位资源以及如何将你的应用集成到OFBiz环境中。 - `<resource-loader>`元素指定如何加载资源。 - `<webapp>`元素定义Web应用程序的元数据,包括名称、...
3. **组件开发**:学习如何创建一个新的组件,以及组件中的主要文件如`ofbiz-component.xml`的用途。 4. **实体模型**:解释OFBiz中实体模型的概念及其作用。 5. **服务定义和服务调用**:如何定义服务并从其他组件...
在上述的`ofbiz-component.xml`文件中,你会看到类似这样的配置: ```xml title="Practice" server="default-server" base-permission="OFBTOOLS" location="webapp/practice" mount-point="/practice" ...
3. **配置服务器端口**:在`D:\ofbiz\framework\base\config`目录下的`ofbiz-containers.xml`文件中,你可以找到OFBiz项目的默认监听端口(默认为8080)。在开发初期,建议保持不变,但如果与Oracle的HTTP服务端口...
- `ofbiz-component.xml`文件用于告知OFBiz框架关于资源的位置配置以及如何加载这些资源。 - `<resource-loader>`元素定义了资源加载器,这里使用的是默认的`component`类型。 - `<webapp>`元素用于配置Web应用...