Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Dependency resolution process in spring framework

    • 0
    • 1
    • 1
    • 2
    • 0
    • 0
    • 0
    • 0
    • 1.05k
    Comment on it

    The Spring IoC container performs bean dependency resolution :

    1. The ApplicationContext is created and initialized with configuration metadata that describes all the beans. Configuration metadata can be specified via XML, Java code or annotations.
      For your batter understanding, Here below I have write following example in XML:

    <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.0.xsd">
    
           <!-- A simple bean definition -->
           <bean id="..." class="...">
               <!-- collaborators and configuration for this bean go here -->
           </bean>
    
           <!-- A bean definition with lazy init set on -->
           <bean id="..." class="..." lazy-init="true">
               <!-- collaborators and configuration for this bean go here -->
           </bean>
    
           <!-- A bean definition with initialization method -->
           <bean id="..." class="..." init-method="...">
               <!-- collaborators and configuration for this bean go here -->
           </bean>
    
           <!-- A bean definition with destruction method -->
           <bean id="..." class="..." destroy-method="...">
               <!-- collaborators and configuration for this bean go here -->
           </bean>
    
           <!-- more bean definitions go here -->
    
        </beans>
    


    2. For each bean, its dependencies are expressed in the form of properties, constructor arguments, or arguments to the static-factory method if you are using that instead of a normal constructor. These dependencies are provided to the bean, when the bean is actually created.


    3. Each property or constructor argument is an actual definition of the value to set, or a reference to another bean in the container.
    You can see example, click on link http://findnerd.com/list/view/-How-to-load-ApplicationContext-in-spring-framwork/1910/


    4. Each property or constructor argument which is a value is converted from its specified format to the actual type of that property or constructor argument. By default Spring can convert a value supplied in string format to all built-in types, such as int, long, String, boolean, etc.
    You can see example, click on link http://findnerd.com/list/view/-Setter-based-and-constructor-based-dependency-injection-in-Spring/1909/


    When the Spring container is created it validate the configuration of each bean. Including the validation of whether bean reference properties refer to valid beans. However, bean properties themselves are not set until the bean is actually created. Beans are singleton-scoped and set to be default are created when the container is created.Otherwise, bean is created only when it is requested.
    The beans creation potentially causes a graph of beans to be created, as the bean's dependencies and its dependencies are created and assigned.
    Spring is trust-able to do the right thing. It detects configuration problems, such as references to non-existent beans and circular dependencies, at container load-time.The bean is actually created when Spring sets properties and resolves dependencies as late as possible. This means that a Spring container which has loaded correctly can later generate an exception when you request an object if there is a problem creating that object or one of its dependencies.


    Thank you.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: