Spring Working principle Exploration

Source: Internet
Author: User

Spring's philosophy is to add Java objects to a framework without affecting the design of Java objects. Let's look at how spring works and see how spring does not affect Java objects.

The EJB framework uses an aggressive (invasive) approach to designing objects that require you to add code that conforms to the EJB specification in your design. Some lightweight cop frameworks, such as Avalon, also require object design to conform to some specification, such as the serviceable interface, which is a typical type 1 practice.

This design requires spring to design the framework in a dynamic and flexible manner. Reflection is used extensively in spring's working principle. One of the first things that spring is going to solve is how to manage beans. Because the IOC thought requires that beans not be able to be invoked directly between them, they should collaborate in a passive way. So the management of beans is a central part of spring's working principles.

Reflection and introspection at the level of the code to think about problems, sometimes can bring unexpected flexibility. But its use is sometimes a philosophical issue, both in ORM Design and in AOP design-whether it's using reflection or code generation.

In spring, the core of dealing with this problem is in the Org.springframework.beans package. And the most central part of it is beanwrapper. Beanwrapper, as the name suggests, is the bean wrapper. So, its main job is to make a call to the settings and methods of attributes (including inline properties) for any bean. In

Beanwrapper's default implementation class Beanwrapperimpl, although the code is longer, the work done is very centralized.

An in-depth study of Beanwrapper

Let's see how this beanwrapper works, assuming we have two beans:

1. public class Company { 
2.  private String name;      
3.  Private Employee Managingdirector;       
4.      
5.    Public String GetName () {
6.    return this.name;     
7.     } 
8.    public void SetName (String name) {
9.    THIS.name = name;     
10.     }
11.    Public Employee Getmanagingdirector () {
12.    return this.managingdirector;     
13.     } 
14.    public void Setmanagingdirector (Employee managingdirector) { 
15.    This.managingdirector = Managingdirector;     
16.    } 
17.      } 
18.     
19.     public class Employee { 
20.  private float salary;       
21.      
22.    public float getsalary () { 
23.  return salary;      
24.     }
25.    public void Setsalary (float salary) { 
26.  This.salary = salary;      
27.    } 
28. }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.