ABOUT
What is Spring

Spring is an open source framework, it was created to address the complexity of enterprise application development
Using the plain-vanilla JavaBeans, Spring makes it possible to achieve things that were only possible with EJBs.

What it has

Lightweight - Its a lightweight in terms of both and size and overhead. Spring is nonintrusive : objects in a Spring-enabled application typically have no dependencies on Spring specific classes.

Modules in Spring:

Core Container - Spring is a container meaning it contains and manages the life cycle and configurations of application objects. In this module, you will find Spring's Bean Factory. A Bean Factory is implementation of factory pattern that applies IoC to separate your application's configuration and dependency specificatons from actual application code.

Inversion of Control - Promotes loose coupling through inversion of control (IoC),  Objects are passively given their dependencies instead of creating or looking for dependencies objects for themselves. You can think of IoC as JNDI in reverse instead of an object looking up dependencies from the container, the container gives the dependencies  to the object at instantiation without waiting to be asked.

Spring's AOP module - Spring comes with rich support for aspect oriented progamming, it is often defined as a programming technique that promotes separation of concerns within a software system. System services such as transactions management, logging and security are commonly referred to as cross-cutting concerns.

Application context module - Bean Factory is what makes Spring a container, added to that the context module is what makes it a framework adding support to Internationalization (I18N) messages, life cycle events and validation.

JDBC and DAO module - This abstracts the jdbc code and keeps your database code clean and simple.

OR Mapping module -  Provides hooks into several popular ORM frameworks, including Hibernate, iBATIS, JDO.

MVC Framework - Spring comes with a full featured Model/View/Controller (MVC) framework for building web applications. It can easily be integrated with other MVC frameworks such as Struts, Spring used IoC to provide clean separation of controller logic from business objects.

Web Module - This is build on the applciation context module providing context for web-based applications. It handles the programmatic binding of request parameters to business objects.





Wiring: Putting together Beans within the Spring Container is known as Wiring.
More about IoC : also referred to as dependency injection.

There are 2 different ways you can inject a dependency.
  1. using the constructor.
  2. using set method.
  3. Interface injection ( not supported by Spring )


More about XML :

<beans>
       <bean id ="test" class="com.darla.Test" >
               // using the set method
               <property name="greeting">
                       <value>Hello</value>
               </property>        
       
               // using the contructor
               <constructor-arg>
                       <value>Hello</value>
               </constructor-arg>

       </bean>
</beans>




More about AOP

  • Aspect: An aspect is a cross cutting concern functionality that is implemented. It is a combination of advice and point cut. Ex: Logging aspect
  • Join Point: A join point is a point in the execution of the application where an aspect can be plugged -in. This point could be Method being called, exception being thrown.
  • Advice: Advice is the actual implementation of the aspect. It is advising the application about the new behaviour, code that implements the actual logging.
  • Pointcut: A point cut defines at what join points  advice should be applied.
  • Introduction: Allows you to add new methods or attributes to existing classes.
  • Target: A target is the class that is being adviced.
  • Weaving: Weaving is the process of applying aspects to a target
               1. Compile
               2. Classload time
               3. Runtime.                





Spring
TAGS
Bean Life Cycle: ( BeanFactory)

  1. If bean implements BeanNameAware interface, then the spring container calls setBeanName() method
  2. BeanFactoryAware interface, then setBeanFactory() method is called
  3. ApplicationContextAware interface , then setApplicationContext() method is called
  4. BeanPostProcessors - PostProcessBeforeInitialization are called
  5. init method -- init-method="setup"
  6. PostProcessAfterInitialization is called
  7. Bean is ready to use

   Shutdown - When the container is about to shutdown

  1. DisposableBean interface , then destroy() method is called
  2. Also the users can have custom destroy method, destroy-method="teardown"

  • By default all the beans are singleton="true" , if false new instance is created for every call, and is also called prototype.

Inner Beans: Also equivalent to inner classes in java. Only accessible to the enclosing class.
       <bean id="test" class="Test">
               <prop name="method1">
                       <bean class="InnerTest"/>
               </prop>
       </bean>

Resource bundle: To handle I18N messages
       <bean id="messages" class="org.springframework.context.support.ResourceBundleMessasgeSource">
               <prop name="basename">
                       <value>training</value>
               </prop>
       </bean>

To invoke this in the application: String msg = context.getMessage("displayName");

       

Narendra Kumar Dantala
A J2EE Developer
Having a masters degree in Computational Science, working in Java, developed applications on different domains such as Finanical Services, B2B, Banking, Utility...