Spring Framework's design concept and design patterns of (from IBM developerWorks China)

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

Spring Framework's design concept and design patterns of (from IBM developerWorks China)

. )

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:

  1. 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.
  2. 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

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:

Spring Framework's design concept and design patterns of (from IBM developerWorks China)

. )

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:

Spring Framework's design concept and design patterns of (from IBM developerWorks China)

. )

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:

Spring Framework's design concept and design patterns of (from IBM developerWorks China)

. )

Bean's analysis and registration process timing diagram is as follows:

Spring Framework's design concept and design patterns of (from IBM developerWorks China)

. )

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:

Spring Framework's design concept and design patterns of (from IBM developerWorks China)

. )

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:

Spring Framework's design concept and design patterns of (from IBM developerWorks China)

. )

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:

Spring Framework's design concept and design patterns of (from IBM developerWorks China)

. )

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.

Back to top

Provided using JSP 2 SimpleTagSupport development ... | Spring Services

  • 11:27
  • View (0)
  • Comments (0)
  • Category: Spring
  • Related Recommendation

Spring Framework's design concept and design patterns of (from IBM developerWorks China)


  • View: 111 times
  • Gender:
  • From: Guangzhou
  • Details book
Search this blog
Recent visitors>> More Visitors



Blog Categories
  • All blog (5)
  • JAVA (1)
  • JQuery (0)
  • WebService (1)
  • Spring (3)
  • Hibernate (0)
Other Categories
  • 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 ...
Latest Comments
Comments list
  • 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 ...

分类:Java 时间:2010-07-07 人气:248
blog comments powered by Disqus


  • Their understanding of the J2EE three-tier architecture (design patterns and software differences between the contact) 2009-06-18

    As Figure 3 layer 1.J2EE points: Server-side business logic (Business Logic Tier, and there is persistent data layers, Businness Tier and the EIS Tier), server-side presentation layer (Web Tier) and express the client layer (Client Tier) J2EE design

  • Their understanding of the J2EE three-tier architecture (design patterns and software differences between the links) 2009-06-21

    As Figure 3 layer 1.J2EE points: Server-side business logic (with Business Logic Tier and data layers of durable, Businness Tier and the EIS Tier), server-side presentation layer (Web Tier), and the client presentation layer (Client Tier) J2EE design

  • Spring Framework's design concept and design patterns (5)-Core Components 2010-08-31

    Keywords: Spring, Core, Components, Context Previous Chapter: Spring Framework design and design patterns (4)-Context Component http://javapub.javaeye.com/blog/751625 Next Chapter: Spring Framework's design concept and design patterns (6)-Ioc contain

  • Design patterns and reusable object-oriented software 2010-07-23

    Seen before in the forum a good blog about design patterns. The most progress also strike while the iron is hot. Learning about design patterns reusable object-oriented software foundation. First give a brief summary of the definition of design patte

  • Structure. Framework. The relationship between design patterns 2010-12-31

    First, the software architecture and framework for the definition of Software architecture of the English word "architecture". Architecture of the basic meaning is the construction, architecture, architectural style. Although software architectu

  • The role of design patterns 2009-04-23

    Excellent system to build a most difficult thing is not the coding (coding), but in early to make the design (design) on the decision. Designed software development life cycle are the key stage, good design can produce good products, but not when the

  • How in practice the use of design patterns free 2009-04-23

    Designed object-oriented programming model is a hot topic, one of many more and more developers who recognize the importance of design patterns. Implementation using design patterns in various languages are also more and more of the article, but a lo

  • Design Patterns Essay Series: opening - model and principles of the [transfer] 2010-05-15

    Transfer from Justin http://www.cnblogs.com/justinw/archive/2006/11/28/574573.html Opening - patterns and principles of design patterns using formal contact preface the past two years, and has been to consolidate what they have learned to write somet

  • Beyond design patterns 2010-10-23

    Depth beyond the outside of the design principles of design patterns Liu Xu Jin , software development engineer, IBM China Software Development Center Liu Xu Jin, IBM China Development Center software engineer, open source software, REST, Web Service

  • Introduction of design patterns grinding 2010-12-20

    First, long-term support to you my sincere thanks to friends! "Grinding Design Patterns" book has been listed specific information, please see the blog post, here is not to say more, lest they think JE has made a reasonable move. Introduction gr

iOS 开发

Android 开发

Python 开发



PHP 开发

Ruby 开发






Javascript 开发

.NET 开发



Copyright (C) codeweblog.com, All Rights Reserved.

CodeWeblog.com 版权所有 黔ICP备15002463号-1

processed in 0.420 (s). 14 q(s)