Spring IoC source code analysis (2) Resource Positioning

Source: Internet
Author: User

Let's take a look at the beanfactory call process.

 
Public class beanfactorytest {public static void main (string [] ARGs) {classpathresource res = new classpathresource ("beans. XML "); xmlbeanfactory factory = new xmlbeanfactory (RES); object OBJ = factory. getbean ("beanfactory"); system. out. println (obj. getclass ());}}

Beans. XML definition

 
<? XML version = "1.0" encoding = "UTF-8"?> <Beans xmlns = "http://www.springframework.org/schema/beans" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi: schemalocation = "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> <bean id = "beanfactory" class = "com. hz. yk. spring. test. beanfactorytest "/> </beans>

Just define yourself.

The classpathresource constructor follows up to set the local path and classload to prepare for the next step.

 
Public classpathresource (string path, classloader) {assert. notnull (path, "path must not be null"); string pathtouse = stringutils. cleanpath (PATH); If (pathtouse. startswith ("/") {pathtouse = pathtouse. substring (1);} This. path = pathtouse; this. classloader = (classloader! = NULL? Classloader: classutils. getdefaultclassloader ());}

First, let's look at the class diagram of classpathresource.

In fact, resource encapsulates the positioning of files and encapsulates them into spring-defined access interfaces. For details, see the implementation of getinputstream (), GetFile (), and other methods.

As you can see, the positioning of resources is actually quite unappealing. The next section will study bean parsing.

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.