Spring---resource access tool class

Source: Internet
Author: User

The class of access resources provided by the JDK does not satisfy the access requirements of various underlying resources, so spring designs a resource interface that provides the application with more powerful access to the underlying resources.

Main methods:

Boolean exists () to determine if a resource exists

Boolean IsOpen () to determine if the resource is already open

URL GetURL () if the underlying resource can be represented as a URL, the method returns the URL object

File GetFile () if the underlying resource corresponds to a file, the method returns the corresponding Files object

InputStream getInputStream () returns the input stream corresponding to the resource

Specific implementation classes:

Bytearrayresource

Classpathresource

Filesystemresource

Inputstreamresource

Servletcontextresource

Urlresource

To access different types of resources, you must use the corresponding resource implementation class, which is cumbersome, and spring provides a powerful mechanism to load resources that automatically identify different resource types

Resource type address prefix:

Classpath loading resources from the Classpath classpath:com/jike/bean.xml

File File:/com/jike/bean.xml

HTTP/http://www.jike.com/bean.xml

FTP Ftp://www.jike.com/bean.xml

No prefix com/jike/bean.xml

Ant-Style matching characters:

? : Match one of the characters in the file name

*: matches any character in the file name

* *: Matching multi-layer paths

Examples of ant-style resource paths:

Classpath:com/t*st.xml

File:d:/conf/*.xml

Classpath:com/**/test.xml

Classpath:org/springframework/**/*.xml

Spring defines a set of interfaces for resource loading and provides an implementation class, as follows

Spring---resource access tool class

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.