Monday, February 28, 2011

How is a typical spring implementation look like


How is a typical spring implementation look like
For a typical Spring Application we need the following files:
·   An interface that defines the functions.
·   An Implementation that contains properties, its setter and getter methods, functions etc.,
·   Spring AOP (Aspect Oriented Programming)
·   A XML file called Spring configuration file.
·   Client program that uses the function.

What are the common implementations of the Application Context


What are the common implementations of the Application Context
The three commonly used implementation of 'Application Context' are
·   ClassPathXmlApplicationContext: It Loads context definition from an XML file located in the classpath, treating context definitions as classpath resources. The application context is loaded from the application's classpath by using the code.
ApplicationContext context = new ClassPathXmlApplicationContext("bean.xml");
·   FileSystemXmlApplicationContext: It loads context definition from an XML file in the filesystem. The application context is loaded from the file system by using the code.
ApplicationContext context = new FileSystemXmlApplicationContext("bean.xml");
·   XmlWebApplicationContext: It loads context definition from an XML file contained within a web application.

What is Application Context


What is Application Context
A bean factory is fine to simple applications, but to take advantage of the full power of the Spring framework, you may want to move up to Springs more advanced container, the application context. On the surface, an application context is same as a bean factory. Both load bean definitions, wire beans together, and dispense beans upon request. But it also provides:
·   A support for internationalization.
·   A generic way to load file resources.
·   Publish events to beans that are registered as listeners.

What is Bean Factory


What is Bean Factory
A BeanFactory is like a factory class that contains a collection of beans. The BeanFactory holds Bean Definitions of multiple beans within itself and then instantiates the bean whenever asked for by clients.
·   BeanFactory is able to create associations between collaborating objects as they are instantiated. This removes the burden of configuration from bean itself and the beans client.
·   BeanFactory also takes part in the life cycle of a bean, making calls to custom initialization and destruction methods.

How many modules are there in Spring? What are they?


 How many modules are there in Spring? What are they?
Spring comprises of seven modules. They are.
·   The core container:
The core container provides the essential functionality of the Spring framework. A primary component of the core container is the BeanFactory, an implementation of the Factory pattern. The BeanFactory applies the Inversion of Control (IOC) pattern to separate an application's configuration and dependency specification from the actual application code.
·   Spring context:
The Spring context is a configuration file that provides context information to the Spring framework. The Spring context includes enterprise services such as JNDI, EJB, e-mail, internalization, validation, and scheduling functionality.
·   Spring AOP:
Spring supports Aspect oriented programming which enables us to perform some desired action just before or after the execution of the specified method
·   Spring DAO:
The Spring JDBC DAO abstraction layer offers a meaningful exception hierarchy for managing the exception handling and error messages thrown by different database vendors. The exception hierarchy simplifies error handling and greatly reduces the amount of exception code you need to write, such as opening and closing connections. Spring Dao’s JDBC-oriented exceptions comply with its generic DAO exception hierarchy.
·   Spring ORM:
Spring provides best Integration services with Hibernate which comply with Spring's generic transaction and DAO exception hierarchies.
·   Spring Web module:
The Web context module builds on top of the application context module, providing contexts for Web-based applications. As a result, the Spring framework supports integration with Jakarta Struts. The Web module also eases the tasks of handling multi-part requests and binding request parameters to domain objects.
·   Spring MVC framework:
Spring comes with MVC web application framework, built on core Spring functionality. This framework is highly configurable and accommodates multiple view technologies like JSP, Velocity, and Tiles. But other frameworks can be easily used instead of Spring MVC Framework.

What are features of Spring


What are features of Spring
·   Lightweight:
spring is lightweight when it comes to size and transparency. The basic version of spring framework is around 1MB. And the processing overhead is also very negligible.
·   Inversion of control (IOC):
Loose coupling is achieved in spring using the technique Inversion of Control. The objects give their dependencies instead of creating or looking for dependent objects.
·   Aspect oriented (AOP):
Spring supports Aspect oriented programming and enables cohesive development by separating application business logic from system services.
·   Container:
Spring contains and manages the life cycle and configuration of application objects.
·   MVC Framework:
Spring comes with MVC web application framework, built on core Spring functionality. This framework is highly configurable and accommodates multiple view technologies like JSP, Velocity, and Tiles. But other frameworks can be easily used instead of Spring MVC Framework.
·   Transaction Management:
Spring framework provides a generic abstraction layer for transaction management. This allowing the developer to add the pluggable transaction managers, and making it easy to maintain transactions without dealing with low-level issues.
·   JDBC Exception Handling:
The JDBC abstraction layer of the Spring offers a meaningful exception hierarchy, which simplifies the error handling strategy. Integration with Hibernate: Spring provides best Integration services with Hibernate.

What are the advantages of Spring framework


What are the advantages of Spring framework
The advantages of Spring are as follows:
·   Spring has layered architecture. Use what you need and leave you don't need now.
·   Spring Enables POJO Programming. There is no behind the scene magic here. POJO programming enables continuous integration and testability.
·   Dependency Injection and Inversion of Control Simplifies JDBC
·   Open source and no vendor lock-in.