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.