Spring Source Learning Note 1

Source: Internet
Author: User

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

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.