In order to maximize the proximity of the spring source and learning, a more direct approach is: directly in the spring source code to add the demo, and debugging.
Referring to the previous experience with spring, Spring's simplest approach is to use an entity class, an XML configuration file, and a test method. For the use of out-of-source code, you need to introduce at least spring-context dependency. So, guess, in the spring source code can be directly in the Spring-context module to add the simplest of the above?
Just do it. In the Spring-context module, create a new entity class (person, under the COM.CYH package), an XML configuration file (Person.xml), and a simple test method (Persontest) with the following structure:
As for the content, it's even easier:
- The content in person is empty (because spring only needs to be a simple Pojo)
- Person.xml file, one line configuration (simplest bean configuration, e.g.)
- Persontest also reads the configuration file directly from the Classpathxmlapplicationcontext, then gets the configured bean and then simply prints
Everything is OK, the console smoothly prints out the following content:
Person.getclass (). GetName (): Com.cyh.Person
The simplest demo code, added to the spring source and successfully run, done ~
Offer yourself a fork from GitHub and "trample" the Spring Source address: Https://github.com/cyhbyw/spring-framework/tree/Branch_v4.2.5.RELEASE
Spring Source Learning: 1th Step-Add the simplest demo code to spring source