Usage of resources

Source: Internet
Author: User
The resources (COM. ibatis. Common. Resource. *) resources class provides an easy-to-use method to load resources from the class path. Processing classloader is a challenging task, especially in the case of application servers/containers. The resources class tries to simplify this work. The resources class is often used in the following situations :? Load an SQL map configuration file, such as a sqlMap-config.xml, from the class path ).? Load the DaO Manager configuration file (such as Dao. XML) from the class path ).? Load various. properties files from the class path. There are many ways to load a resource, including :? For simple read-only text data, load as reader.? For simple read-only binary or text data, load as stream.? For binary or text files that can be read and written, load as file.? For Read-Only configuration Property Files, load as properties.? For read-only general resources, load as a URL. In the preceding order, the resources class can load resources as follows: reader getresourceasreader (string resource); stream getresourceasstream (string resource); file getresourceasfile (string resource ); properties getresourceasproperties (string resource); Url getresourceasurl (string resource); in each of the preceding methods, the same classloader is used to load resources and resources, or, if it fails, the system classloader will be used. In some environments (such as some application servers), classloader may be troublesome. You can specify the classloader used (such as the classloader used to load the application ). Each method above has a classloader as a parameter. They are: reader getresourceasreader (classloader, string resource); stream getresourceasstream (classloader, string resource); file category (classloader, string resource); properties getresourceasproperties (classloader, string Resource); Url getresourceasurl (classloader, string resource); the resource Parameter Name of the preceding method should be a fully qualified name, plus the full file/Resource Name. For example, if the class path contains the resource "com. domain. mypackage. mypropertiesfile. properties ",Code Loading http://www.ibatis.com Clinton begin translated by Liu Tao (toleu@21cn.com) Development Guide ibatis SQL maps page 59 of 62 resources for properties (note that a slash/is not required before the resource name /). String resource = "COM/domain/mypackage/mypropertiesfile. properties "; properties props = resources. getresourceasproperties (Resource); similarly, you can load the SQL map configuration file from the class path as a reader. Suppose it is in the properties directory of the class path (properties. sqlMap-config.xml ). String resource = "properties/sqlMap-config.xml"; reader = resources. getresourceasreader (Resource); sqlmapclient sqlmap = xmlsqlmapbuilder. buildsqlmap (Reader );
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.