Spring 4 Introduction and example

In this video we are introducing you with the Spring 4 Framework and then teaching you to make your first application in Eclipse


 
Ads

Spring 4 Introduction and creating example in Eclipse

In this video introduction to Spring 4 Framework, we are explaining you the Spring 4 framework and explained you the code for first Spring Bean based application. You will learn how to create your first Bean, configure it and run it from Eclipse IDE.

I am assuming that you have prior experience with Core Java, Advanced Java and application development using Eclipse IDE.

This video tutorial is for total beginner in Spring Framework, through this video you will learn the basics of Spring framework. Through this video we are teaching you to develop your first Spring 4 application.

We are creating a simple bean then configuring the bean and finally running it. Eclipse IDE is used for developing and running this application. Maven tool is used for satisfying the Spring dependency in the project. Maven will automatically download Spring 4 library files, you don't have to download spring jar files manually.

Video: Introduction to Spring 4 and Creating first application:

Spring Framework

Welcome to our channel

Today we will learn about the Spring Framework. I will introduce you with the famous Spring Framework. If you have not subscribed our channel please subscribe it now.
So, let’s get started

Spring Framework over view:

Spring Framework is Open Source Framework originally developed by Rod Johnson Based on book “Expert one-on-one J2EE Design and Development” (October, 2002).

The Spring Framework is licensed under the terms of the Apache License, Version 2.0 and can be downloaded at: http://www.springframework.org/download

Spring framework tutorial

Now we will see what is Spring Framework?

  • Spring Framework is Open Source Java based application development framework extensively used for developing enterprise applications.

    Spring Framework is very popular light-weight framework used by developers around the world to develop and deploy enterprise ready business applications.

    Spring framework is modular framework which can be used to configure declarative transaction management, dependency management, mailing facility and other functionality in the application.

    This framework is also used to manage and configure the persistence layer in the application

  • Spring Framework is IoC container in Java. The term IoC stands for inversion of control. This framework is Inversion of Control and Dependency Injection framework. For example in an application which needs database access you can define the Database Connection as one of the dependency in your code. Then configure the database connection in Spring Configuration. Spring Framework will create the JDBC connection object in runtime and connect to database. This database connection will be passed on to your code where you need the Connection. This way Spring framework work as Dependency Inject and Inversion of Control framework.
  • Spring also has the AOP framework which is and implementation AOP Alliance interface in the Java. Spring AOP is used for modularizing the cross-cutting concerns in aspects. Spring AOP is a poxy-based  runtime framework which is very easy to use in Java programs. The Spring AOP takes the full advantages of Spring IoC container.
  • Spring Framework is modular framework with 20 modules.

Why is Java Spring framework called as "lightweight" framework?

The term "lightweight” is a concept through with we are defining the weight of a Framework. If a framework is “lightweight” then it will have minimal impact to the Application.

Spring Framework is “Lightweight” framework as it has minimal impact to an application. So, there is minimal code change if the framework is implemented on the existing code.

Reason for "light-weight“: Spring comes with modular approach and its divided into 20 modules such as:

  • Spring Core
  • Spring JDBC
  • Spring MVC
  • Spring Data
  • Spring ORM, etc

User can selectively use the modules in their project.

Why to use Spring Framework?

Here is points that describes why to use the Spring Framework?

  • Spring framework is modular: Spring Framework is modular framework and it allows you to selectively use the components you want.
     
  • Spring framework is non-invasive: It means that it does not force the developers to implement or extend the Spring API in application.
     
  • Spring is light-weight framework: Spring is light-weight framework and it is based on the POJO classes; Spring framework knows how to inject dependencies in run-time.
     
  • Spring Framework is popular due to its simplicity
     
  • Spring Framework great feature for the testing of your application
     
  • Spring framework is loosely coupled framework

Spring Framework was initially started to ease the development of J2EE based application by providing the environment, API and valuable services.  Spring is matured Framework and currently it is one of the most used framework in Java. It allows the many other frameworks to work together in a coherent manner.

Modules of the Spring Framework

The Spring Framework is collection of 20 loosely coupled sub modules. You can consider Spring Framework as a collection of frameworks-in-the-framework. Important modules of Spring are:

Core - Inversion of Control (IoC) and Dependency Injection
AOP - Aspect-oriented programming
DAO - Data Access Object support, transaction management, JDBC-abstraction
ORM - Object Relational Mapping data access, integration layers for JPA, JDO, Hibernate, and iBatis
MVC - Model-View-Controller implementation for web-applications

Remote Access, Authentication and Authorization, Remote Management, Messaging Framework, Web Services, Email, Testing, etc are other modules of Spring Framework.

Spring modules organization

In Spring Framework all the modules are organized into separate package.
These packages are:

  • Spring Core
  • Spring DAO
  • Spring Context
  • Spring AOP
  • Spring ORM
  • Spring Web and
  • Spring Web MVC

How to create first program?

Create a Java Bean with following Definition
public class BasicBean {
  private String mesg = "Spring is simple";
  public String getMessage() {
    return mesg;
  }
  public void setMessage(String mesg) {
    this.mesg = mesg;
  }
}

Spring configuration file

Spring configuration is done through .xml file (Context.xml)

This simple Java class has a variable mesg for storing message and getter and setters.
The code:

<bean id="basic" class="net.roseindia.BasicBean" />
is used to define a bean in the xml file.

Running the example

Here is code for running the example

import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class BasicBeanTest {
  public static void main(String[] args) {
  BeanFactory beanfactory = new ClassPathXmlApplicationContext("context.xml");
  BasicBean bean = (BasicBean) beanfactory.getBean("basic");
  System.out.println(bean.getMessage());
  }
}

Here we are creating object of BeanFactory and then getting the bean defined in xml file with the help of mthod getBean().
After getting the bean object we can call the getMessage() method and it returns the data set in the Bean.

In this video you learned the basics of Spring Framework and created simple project that demonstrate the use of Spring Framework.

Download Source code of the Project.

Next: Check all the tutorials of Spring 4 Framework

Advertisements

Ads
Share on Google+Share on Google+

Spring 4 Introduction and example

Posted on: March 7, 2017 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

 

Discuss: Spring 4 Introduction and example  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0

Ads

 

Ads