The two most core classes in 1.Spring
1) defaultlistablebeanfactory
Xmlbeanfactory inherited from Defaultlistablebeanfactory,defaultlistablebeanfactory is the core part of the entire bean load and is the default implementation of Spring load and register bean
2) Xmlbeandefinitionreader
2. Sample Code
Beanfactory bf=new xmlbeanfactory (New Classpathresource ("Beanfactorytest.xml"));
Xmlbeanfactory.class
Public classXmlbeanfactoryextendsDefaultlistablebeanfactory {Private FinalXmlbeandefinitionreader Reader; PublicXmlbeanfactory (Resource Resource)throwsbeansexception { This(Resource, (beanfactory)NULL); } PublicXmlbeanfactory (Resource Resource, Beanfactory parentbeanfactory)throwsbeansexception {Super(parentbeanfactory); This. Reader =NewXmlbeandefinitionreader ( This); This. Reader. loadbeandefinitions (Resource); }}
loadbeandefinitions (Resource Resource) throws Beandefinitionstoreexception {
return this. loadbeandefinitions (New Encodedresource (Resource));
}
loadbeandefinitions (Encodedresource Encodedresource) {
....
InputSource InputSource = new InputSource (inputstream);//parsing an XML file by means of sax
....
This.doloadbeandefinitions (InputSource, Encodedresource.getresource ());
}
3. Encapsulation of configuration files
Implements Inputstreamresource
4.Abstractautowirecapablebeanfactory.ignoredependencyinterface()
Ignoring the automatic assembly function for a given interface
5. Load Bean
protected intDoloadbeandefinitions (InputSource InputSource, Resource Resource)throwsbeandefinitionstoreexception {Try { intValidationmode = This. Getvalidationmodeforresource (resource);// Gets the validation mode of the XML file document Doc= This. Documentloader.loaddocument(InputSource, This. Getentityresolver (), This. ErrorHandler, Validationmode, This. Isnamespaceaware ());// load XML file return This. registerbeandefinitions (Doc, Resource);// Returns information about the registered bean }Catch(beandefinitionstoreexception var5) {ThrowVAR5; } Catch(saxparseexception var6) {Throw NewXmlbeandefinitionstoreexception (Resource.getdescription (), "line" + var6.getlinenumber () + "in XML document from" + Res Ource + "is invalid", VAR6); } Catch(saxexception var7) {Throw NewXmlbeandefinitionstoreexception (Resource.getdescription (), "XML document from" + Resource + "is invalid", VAR7); } Catch(parserconfigurationexception var8) {Throw NewBeandefinitionstoreexception (Resource.getdescription (), "Parser configuration exception parsing XML from" +resource, VAR8); } Catch(IOException var9) {Throw NewBeandefinitionstoreexception (Resource.getdescription (), "IOException parsing XML document from" +resource, VAR9); } Catch(Throwable var10) {Throw NewBeandefinitionstoreexception (Resource.getdescription (), "Unexpected exception parsing XML document from" +resource, VAR10); } }
1) Get the validation mode of the XML file
2) Load XML file
3) Return the information of the registered bean
Spring Source Learning Note 1