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.
Back to top
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 ...
Related Posts of Spring Framework's design concept and design patterns of (from IBM developerWorks China)
What is a Design Pattern Design patterns are a set of re-use, most people know, after cataloging, code design experience. For the use of design patterns are reusable code, so that the code more easily understood by others, and ensure the reliability code.
Software development process at the design and coding, both organizations (as well as other details of the project controllability requirements) engineering method is XP ah, UPS ah what the design phase is to cover the entire software development pro ...
Excerpt from: http://blog.csdn.net/exceljava/archive/2007/10/05/1811925.aspx Download the spring package of documents and a variety of packages large projects are often at only some of which we must, if not sure what package when necessary, then take a lo
If you do not want to use the default hibernate.cfg.xml file as a configuration file, we can also specify the configuration file name: File file = new File ( "C: \ \ myhibernate.xml"); Configuration config = new Configuration (). Configure (file
I hate the thought of the time to teach some provide a lot of code, because I think the thought process of acceptance should be a pleasure to read as a novel process, rather than spend a lot of brain power for a certain process details And this world ...
AspectJ directory are in the Spring framework to use AspectJ source code and test program files. AspectJ is the first java application framework provided by the AOP. dist directory is a Spring release package, regarding release package described below in
Master the ability to reuse code very familiar with the new API's fast. This is because, he once used a lot of the API, have a lot of reusable code. He knows what is available and what is deficient. He has been using Qt, also used by gtk +, also used
The end of the project stage, the client suddenly put forward a very troublesome but normal demand, the system records all changes must be carried out. Formats such as: 2004.1.1 12:30 Ikuya wind orders Sales Order Date 2004.1.2-> 2004.1.3 The firs ...
Before a friend also wanted to study development of FLEX. Asked me to help him to be a small sample. Spent a weekend time, to integrate a sampleproject. Client: FLEX Server: Spring2.5 + Hibernate3.2 + Hibernate-annotations3.3.1 + MySQL5 FDS: BlazeDS3 IDE:
First, Appfuse brief introduction Matt Raible are Appfuse developed a guiding entry-level J2EE framework, how to integrate its popular Spring, Hibernate, ibatis, struts, Xdcolet, junit, etc. give the basic framework of the model, the latest version 1.7 is