Featured Posts

Sunday, May 29, 2016

Advantage of ApplicationContext over BeanFactory in Spring

- No comments

         Beans and Context are two most important packages in Spring Framework. Both BeanFactory and ApplicationContext are used for the same purpose to work as Spring IOC Container.
         The BeanFactory provides advanced configuration mechanism capable of managing beans whereas the ApplicationContext builds on top of BeanFactory with some addition functionality such as event propagation, message resource handling & easier integration with Springs AOP features.
         Beans can be configured in the Spring IoC container through XML files, Properties files, Annotations, or even APIs. Spring Container reads these beans by using BeanFactory or ApplicationContext. 
         If we have defined our Beans in the Spring.xml, then BeanFactory or ApplicationContext needs to read the Spring.xml to load the Beans in container. 

Bean factory: 

        It is a container which instantiates, configures, and manages a number of beans which establishes dependencies between themselves. 
        BeanFactory interface's implementation class XmlBeanFactory is to create and initialize the factory bean and ClassPathResource to load the bean configuration file.To load the Bean configuration in the container  using BeanFactory, It requires ResourceObject interface which will provide the XML file.

Example: 


ApplicationContext:

       An interface for providing configuration information to an application. Likely the most advanced spring container, provides all the features of BeanFactory along with extra features to resolve textual messages from a Properties File and publish application events to interested Event listeners.
      ApplicationContext implementations are FileSystemXmlApplicationContext, ClassPathXmlApplicationContext, WebXmlApplicationContext .


       Here Spring.xml is the spring configuration file and “sringdemo” is a bean defined in that spring configuration file.we have used ClassPathXmlApplicationContext, which is an implementation of ApplicationContext interface in Spring.

Here are some basic differences:

  1. BeanFactory is core components of Spring IoC container and is recommended for lightweight framework like Mobile and Applet
  2. ApplicationContext extends BeanFactory so ApplicationContext is more powerful than BeanFactory. ApplicationContext is preffered to be used while developing J2EE Entreprise applications
  3. ApplicationContext allows more than one config files to exist while BeanFactory only permits one.
  4. ApplicationContext can print Events to Beans registered as listeners. This feature is not supported by BeanFactory.
  5. ApplicationContext also provides support for application of Life-cycle events, internationalization messages and validation and also provides services like EJB integration, remoting, JNDI access and scheduling.These features too are not supported by Bean Factory.

Saturday, May 28, 2016

Spring Framework Architecture

- No comments

          Spring Framework is application framework that provides comprehensive infrastructure support for developing Java Enterprise applications as well as robust/High end web applications. Spring handles the infrastructure so you can focus on your application.
         It enables you to build applications from "Plain Old Java Objects" (POJO's) and to apply enterprise services non-invasively to POJO's. This capability applies to the Java SE programming model and to Java EE.

Advantages of using Spring Framework :
  1. Without having to deal with transaction APIs, A Java method execute in a database transaction .
  2.  A local Java method can be remote procedure without having to deal with remote APIs.
  3. Make a local Java method a management operation without having to deal with JMX APIs.
  4. Java method can be a message handler without having to deal with JMS APIs.

Architecture & Modules: 

     The Spring Framework features organised into 20 about modules. These modules are grouped into Core container , Data Access/Integration, Web, AOP(Aspect Oriented Programming) , Instrumentation, and Test as given in the below diagram.

Core Container :

It has four modules as Core, Beans, Context, Expression Language(EL).
Core : It provides the fundamental features of the framework such IoC and Dependancy injection features.
Bean: It provides BeanFactory which is an implementation of the factory pattern. 
Context: It builds on the solid base provided by the core and Beans Modules,It is a means to access objects in a framework style manner similar to JNDI Registry.It supports internationalization (I18N), EJB, JMS, Basic Remoting.
Expression Language(EL) : It provides a powerful expression language for querying and manipulating an object graph at runtime.It provides support to setting and getting property values, method invocation, accessing collections and indexers, named variables, logical and arithmetic operators, retrieval of objects by name etc.

Data Access/Integration: 

It comprises of JDBC, ORM, OXM, JMS and Transaction modules. These modules basically provide support for interaction with the databases.
JDBC(Java Database Connectivity): It gives a JDBC-abstraction layer that removes the need to do monotonous JDBC related coding.
ORM(Object Relational Mapping): It gives integration layers for mostly used object-relational mapping APIs such as JPA, JDO, Hibernate, and iBatis.
OXM(Object/XML Mapping): It gives an abstraction layer that supports Object/XML mapping implementations for JAXB, Castor, XMLBeans, JiBX and XStream.
JMS(Java Messaging Service): It gives all the features for producing and consuming messages using Websphere MQ or any other middleware.

Spring Web: 

It has four modules likes Web, Servlets , Portlet, Websocket
Web: Provides support for features like file multipart file-upload functionality , the initialization of the IoC container using servlet listeners and a web-oriented application context.
Servlet: It is also know as spring mvc and has Spring's model-view-controller (MVC) implementation for web applications.
Portlet: Provides the MVC implementation for Spring based Portlets
Web-Socket:  Provides support for WebSocket, two-way communication between client and server in web applications.

      Also Spring has some important modules like AOP (Aspect Oriented Programming), Aspects, Instrumentation, Messaging.
AOPAspect Oriented Programming): Aspect Oriented Programming is sensibly new and it is not a replacement for Object Oriented ProgrammingAOP is another way of organizing your Program Structure. AOP is a Prominently used for separating crosscutting concerns like logging.
Test: This module helps in Testing purpose of the application. It supports unit testing and integration testing with other framework like jUnit and TestNG.


Tuesday, July 15, 2014

Because I’m happy...Happiness is starts from home

- No comments
It might seem crazy what I’m about to say
Sunshine she’s here, you can take a break
I’m a hot air balloon that could go to space
With the air, like I don’t care baby by the way

Because I’m happy
Clap along if you feel like a room without a roof
Because I’m happy
Clap along if you feel like happiness is the truth
Because I’m happy
Clap along if you know what happiness is to you
Because I’m happy
Clap along if you feel like that’s what you wanna do
.....
A song By PHARRELL WILLIAMS

              Every time i listen to this song, It makes me feel what life really meant for....Regardless of whether we live in the US, India or anywhere else, family is the building block of any society, and our greatest fulfillment lies there. Of course, one needs to give due importance to work. But if any society works diligently in every other area but neglects the family, it would be the same as straightening deck chairs on the Titanic.

             We all seek happiness but what most of us discover is that happiness is a home-made product. If you have strong and effective relationship with family members - whether living together or apart - the resultant good vibes and mental solace tend to overflow into all other aspects of life. When your family is heading in the right direction, you are better able to perform and focus at work. On the other hand, if things aren't going well at home, it is difficult to be deeply happy anywhere else. Thus, it is supremely important that at home, with your family, you concentrate on creating a beautiful family culture....