The preface of the Spring series of dead Knock
The Spring Series blog is a source-level reading for spring. Since the work, have been in touch with the spring framework, it can be said that the use of the Spring framework configuration is very skilled. Personal feeling: Spring technology is very powerful, simple XML tag configuration, can open very powerful support functions, covering all aspects of the EE enterprise application. Use is used, but it is designed and implemented on the spring floor, smattering. "What a great design it is to make spring omnipotent and all-encompassing." Finally, I have the power to study spring source.
Read any one of the framework of the source code, in fact, and ordinary business systems, are a reverse engineering, time-consuming power. Although there are a lot of spring related books, but most of them are about how to use the book, the spring Source analysis of the book is very few. The crowd found him 1100 degrees, "Spring Source depth Analysis" formally I need it. Of course, I grind the spring source, will also refer to a lot of information and books, and finally form their own knowledge framework, and finally record the results, that is, this series of blogs.
Grinding spring source, said before, time-consuming, but there will be a great harvest.
1. Warm knowledge of the new, can deepen the understanding of the past spring application
2. Familiar with spring's intrinsic mechanism, learn the extensibility and implementation of design ideas, can improve the personal system design capabilities.
3. At the technical level, it is possible to explore some common design patterns and how they landed.
4. Improve the ability of reading source
5. Multiple interview experience shows that as a veteran of old birds, how to use spring light is far from enough, these just work will.
The main contents and features of the spring series
1. Do not copy and paste the source of large tracts
2. Re-design ideas and patterns
3. Reverse Programming Tool:Architexa
4. Description tool: Design class diagram, sequence diagram, flowchart
5. Learning Process: Example + bold personal hypothesis + source argument
6. In-depth
1. Understand the factory model and realize the benefits of the factory model
It is well known that the whole spring container is actually a big factory. Before you introduce beanfactory, you need to know what the factory model is.
The factory model provides an interface for creating objects, divided into three categories
1. Simple Factory mode (Factory)
2. Factory mode (Factory method)
3. Abstract Factory mode (Factory)
In the case of a simple factory, the other 2 factory models are similar, and the importance of understanding what is the meaning of working mode.
1.1 Class Diagram
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/78/1D/wKioL1Z2QH3BoLYIAAAi0pzAgyg568.png "title=" Clipboard.png "alt=" Wkiol1z2qh3bolyiaaai0pzagyg568.png "/>
1.2 Simple Factory mode
As the name implies, the pattern itself is simple, and is used in the case of simpler business.
It consists of three characters (see the following class diagram for a relationship):
1, factory class role: This is the core of this model, contains a certain business logic and judgment logic. In Java it is often implemented by a specific class.
2, abstract product role: it is generally the specific product inherits the parent class or implements the interface. Implemented in Java by an interface or an abstract class.
3. Specific product roles: the object created by the factory class is an instance of this role. Implemented in Java by a concrete class.
public class McChicken Implements food{/* * Get a copy of the chicken */public void get () {System.out.println ("I want a copy of the wheat Incense Chickens "); }}
Public interface Food {/* * get the appropriate foods */public void Get ();}
public class Chips Implements food{* * Get a copy of French fries */public void get () {System.out.println ("I want a French fries"); }}
Public class simplefactory { public static food getfood ( String type) throws InstantiationException, IllegalAccessException, Classnotfoundexception { if (Type.equalsIgnoreCase (" McChicken ")) { return McChicken.class.newInstance (); } else if ( Type.equalsignorecase ("Chips")) { Return chips.class.newinstance (); } else {            SYSTEM.OUT.PRINTLN ("Oops! The corresponding instantiation class could not be found! "); return null; } }}
1.3 Significance
The creator and consumer of simple Factory mode separation products is advantageous to the optimization of software system structure. Of course, the simple factory model also has its own shortcomings, because and the theme does not repeat. Spring provides an object factory interface, which is beanfactory, similar to the simple factory model described above, but more powerful than his.
2. Understand the factory model and realize the benefits of the factory model
Before you start learning the source code, you need to have work to do.
1. Prepare the source code
2. Prepare the Ide+ build tool
3. Installing architexa
4. Configure the environment and run a spring version of "HELLO World"
5. Log
2.1Class file
Users public class User {private String userName; Private String Email; Private list<card> cardlist, ...} Bank card public class card {private int cardno; Private String Bank; private int type; ...}
2.2 Configuration file Iocbeanfactorytest.xml
<?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-3.1.xsd "> <bean id= "Beijingcard" class= "Com.spring.examples.ioc.bean.Card" > <property name= "CardNo" Value= "6220-52103-4123-456" ></property> <property name= "bank" value= "Beijing Banking"/> </bean> <bean id= "JiansheCard" class= " Com.spring.examples.ioc.bean.Card "; <property name= "CardNo" Value= "6227-52103-4123-456" ></property> <property name= "bank" value= "CCB"/> </bean> <bean id= "Miyue" class= " Com.spring.examples.ioc.bean.User " primary=" true " scope=" Singleton "> <property name= "UserName" value= "芈 Month" > </property> <property Name= "Email" value= "[email protected]" ></property> <property name= "Cardlist" > <list> <ref bean= " Beijingcard "/> <ref bean= "Jianshecard"/> </list> </property> </bean></beans>
2.3 Test class
Public class iocbeanfactorytest { public static void main (String[] args) { DefaultListableBeanFactory Factory = new defaultlistablebeanfactory ();//Construction Plant xmlbeandefinitionreader reader = new xmlbeandefinitionreader (Factory);//new XML reader reader.loadbeandefinitions (New classpathresource (" Iocbeanfactorytest.xml "));//rules register into the container object bean = factory.getbean ("Miyue"); if (Bean!=null) { User miyue = (User) bean; system.out.println (Miyue.getEmail ()); system.out.println (Miyue.getusername ()); list<card> cardlist = miyue.getcardlist (); for (card c:cardlist) { system.out.println (c); } } }}
return results
[Email protected]
芈 Month
[Email protected]
[Email protected]
At this point, you can formally embark on the journey of reading the source.
This article is from a "simple" blog, so be sure to keep this source http://dba10g.blog.51cto.com/764602/1726509
One of the Spring Series: ready to read the spring source environment