Description: Spring Framework as one of the best now, has been widely used, and the analysis of many of its articles. This paper will attempt to analyze another perspective on the Spring Framework Spring Framework design design bone structure, there are several core components that? Why do we need these components? Is how to combine them together constitute the skeleton structure of Spring? Spring's AOP feature is based on the use of the bone structure to work? Spring in the further use of those design patterns to complete it this design? It's that the future of our design concepts, software design what inspiration? This article will answer these questions in detail.
Release Date: June 10, 2010
ApplicationContext can be seen from the diagram above inherited BeanFactory, which explains the main run Spring container object is Bean, another inherited ApplicationContext ResourceLoader interface allows access to the ApplicationContext any external resources, which will be described in detail in the Core.
ApplicationContext subclass mainly includes two aspects:
- ConfigurableApplicationContext said the Context is to modify the, that is, the user can dynamically build Context Zhong add or modify an existing configuration information, Ta there are more than the following subsets of the most frequently used is to Gengxin of Context, Ji AbstractRefreshableApplicationContext class.
- WebApplicationContext name suggests, is to prepare the Context web that he can direct access to the ServletContext, usually, less use of this interface.
Further down is in accordance with the Construction of Context sub-file types, then that is the way to access Context. Such a level Context constitute a complete hierarchy.
Overall, ApplicationContext must complete the following things:
- Identifies an application environment
- Bean object created using BeanFactory
- Save the object relationship table
- Able to capture events
Context as the Ioc Spring container, basically most of the features Spring integration, or the basis for most functions.
Core components of the core components as the Spring, he includes a number of key categories, which is an important part of the definition of the resource access. That all resources are abstracted way of an interface is worth the design brought in later to learn. The following look at the important role of this part of the Spring.
The figure is Resource-related class structure diagram:
Resource can be seen from the map interface to package a variety of possible resource types, which is blocked to users in different file types. Providers of resources, how to wrap up their resources to other people use it is also a problem, we see Resource interface inherits InputStreamSource interface that in a month getInputStream method returns the InputStream Class . So that all resources are able to obtain through InputStream of this class, it also shields the provider of resources. Another problem is the loaded question of resources, that is, who should be uniform loading of resources, this task can be seen from the diagram above is ResourceLoader interface, Wan Cheng, he blocked all of the resources of those differences in loading, only need to implement this interface can load all the resources, and his default implementation is DefaultResourceLoader.
Context and Resource Here is a look at how to build relationships? First of all, look at their class diagram:
Apart from this chart found in the related class BeanFactory, but also found that the register associated with the Bean. This method has a line in refreshBeanFactory loadBeanDefinitions (beanFactory) will find the answer, this method will start loading, parsing the definition of Bean, that is, the user-defined data structure into Ioc container-specific data structure.
This process can explain the timing diagram below:
Bean's analysis and registration process timing diagram is as follows:
After the BeanFactory is created, and the latter to add some Spring itself requires some tools, this operation is completed in AbstractApplicationContext the prepareBeanFactory method.
AbstractApplicationContext the next three lines of code in the function expansion of Spring played a crucial role. The first two lines is designed to allow you can now build the BeanFactory configuration has been modified so the back line is you can later create Bean instance of an object to add some custom actions. So they are expanding the Spring functionality, so we have to learn to use a part of Spring must be clear about this.
Which is mainly in the invokeBeanFactoryPostProcessors method for achieving BeanFactoryPostProcessor interface subclass. And implementation of its postProcessBeanFactory method that statement as follows:
If it is ordinary Bean directly create an instance of him is by calling the getBean method. Bean instance is created the following timing diagram:
There is also a very important part is to establish the relationship between object instances Bean, which is Spring Framework's core competence, when, how to establish the relationship between them Consider the following timing diagram:
Ioc Container extension points
Another problem now is how these objects have a certain Bean scalability, that is, some operations can be added to the user. What are extension points? Spring is how to call these extension points?
On Spring's Ioc container, the main there are so few. BeanFactoryPostProcessor, BeanPostProcessor. They are in the building and construction Bean BeanFactory object call. There is InitializingBean and DisposableBean They are created and destroyed in the Bean instance when called. Users can implement the methods defined in these interfaces, Spring will call them at the appropriate time. Another is that he is a special FactoryBean Bean, the Bean can be the user more control.
These extension points usually we use Spring to complete our specific tasks De Di Fang, Ruhe proficient in Spring to see you have a good Spring has not Zhangwo what extension points, and how to use them, to know how to use them is important to understand their inherent Ji Li. Can use the following analogy to explain.
We Ioc container compared to a box, this box has a number of balls in the mold, the mold can be used to create many different balls, and a model making these ball machine, this machine can produce ball mode. Then the correspondence between them is the BeanFactory is the model that made the ball machine, ball mold is Bean, and the ball out of the ball is molded Bean instance. It said earlier a few extension points again in place? BeanFactoryPostProcessor corresponds to the model to be made when making the ball come out, you will have the opportunity to make a set when its amendments, that is, the ball he can help you modify the model. The InitializingBean and DisposableBean ball molded in the beginning and end stages of the ball, you can do some preparation and mopping up. BeanPostProcessor can give you the ball out of the ball molding to make appropriate amendments. Finally, there is a FactoryBean, but it is a magical ball mode. Not advance the ball on the shape of the mold, but to give him to you to determine its shape, since you can determine the shape of the spherical model, of course, he made sure the ball is out of the ball you want, so in this case Rini can find all you want the ball
Ioc container how to use them
Introduction to the Spring container in front of the building process, that Spring can do for us, Spring of Ioc container they do? We use Spring Ioc container must be constructed first, Spring can not work without it, ApplicatonContext.xml Ioc container is the default configuration files, Spring features all the features are based on the work of the Ioc container, such as the back to introduce the AOP.
Ioc it actually is for you to build a cube, Spring for you and setting up the bone structure, the cube in the end what good things can come out of change, which must have your participation. Then how do we participate? This is the front said to understand that some expansion in the Spring, we realize that through the extension point to change the general behavior of Spring. As for how to implement extension points to get the results we want personality, Spring there are many examples in which AOP implementation is Spring itself to achieve its expansion points to achieve its desired characteristics of functions that can be used to refer to.
Provided using JSP 2 SimpleTagSupport development ... | Spring Services
- View (0)
- Comments (0)
- Category: Spring
- Related Recommendation
- View: 111 times
- From: Guangzhou
- Details book
Search this blog
Recent visitors>> More Visitors
- All blog (5)
- JAVA (1)
- JQuery (0)
- WebService (1)
- Spring (3)
- Hibernate (0)
- My Favorites (0)
- My Forum Topics Posts (0)
- I posted all the forums (0)
- I am the essence of a good paste (0)
Recently joined the circle
- 2010-07 (2)
- 2010-06 (2)
- 2010-04 (1)
- More archives ...
- Spring Framework's design philosophy and design model analysis (Abstract ...
- Provided using JSP 2 SimpleTagSupport development ...
- Json format string will be converted to Map format
- Spring Service
- WebService processing. Net solution to the problems in the Dataset ...