Spring Architecture – An Introduction

Spring Architecture – An Introduction:
Spring is a lightweight framework used to build java applications. In this article let us see the Spring Architecture in detail.

architecture

There are seven modules in Spring,

  • Core
  • ORM
  • DAO
  • AOP
  • MVC
  • Application Context
  • Web Context

CORE:
This forms the base of Spring framework. All the other modules are built over Core module. This module contains Bean factory container which forms the basis to implement Dependency Injection.

DAO:
Data Access Object – This module provides a standard way for data access. (Hibernate, JDBC etc..).  Normally in an application to access the database we need to opening connection, perform the operation and close the connection. But in Spring DAO, We can overcome this issue’s because Spring takes care of opening and closing of database connections and all we have to do write code to perform the operations.

ORM:
Object Relational Mapping – This helps us to integrate Spring framework with other Frameworks such as Hibernate, JDO etc.

AOP:
Aspect Oriented Programming – Helps in implementing aspects within our application. Aspect Oriented Programming helps us to separate application logic from system level services.

MVC:
Model View Controller – This module helps us to separate application logic from the view.

Application Context:
This module is built over Core Module. Application Context has all the concepts of Bean factory and in addition to those concepts application context has internalization of Messages, life cycle events and validation

Web Context:
Web Context is a part of web application which includes MVC module.

Read More

Dependency Injection in Spring Example

Dependency Injection in Spring Example
Here is the code for Dependency Injection in Spring. This code is tested using NetBeans 8.0.2.

Dependency Injection:
Dependency Injection is a process where the Object define its Dependencies, that is with the Objects they work with.

Tightly Coupled vs Loosely Coupled
Tightly Coupled: 

In tightly coupled objects interdependent on each other, So when a change is one Object requires changes to number of other objects.

Loosely Coupled:
In Loosely coupled, Reduces the inter-dependencies of the Objects, that is, Change made in one object does not require to make changes in other objects.

Types of Dependency Injection:
There are two ways in Dependency Injection,

  • Setter Injection
  • Constructor Injection

Create Project:
File –>New Project –>Java –>Web Application
Give a name to Web Application and click Next–>Next–>
Choose the Framework Spring and click Finish

Required Folders:
Right click the Source Packages and Create 2 Java Packages and name them as
1) Dao
2) SimpleValues

Inside Dao create a Java Class and name it as Studentdao.java
Inside SimpleValues create java class and name it as Student.java

Directory Structure
DI

Student.java

applicationContext.xml

Studentdao.java

Output:
output

 

 


Read More