Download as pdf or txt
Download as pdf or txt
You are on page 1of 36

SPRING FRAMEWORK

WHY TO LEARN SPRING

Spring is the most popular application


development framework for enterprise Java.

Millions of developers around the world use


Spring Framework to create high performing,
easily testable, and reusable code.
WHAT IS SPRING

Spring is a lightweight framework. It can be thought of as


a framework of frameworks because it provides support to various
frameworks such as Struts, Hibernate, Tapestry, EJB, JSF, etc.

The framework, in broader sense, can be defined as a structure


where we find solution of the various technical problems.

The Spring framework comprises several modules such as IOC,


AOP, DAO, Context, ORM, WEB MVC etc.
WHO DEVELOPED SPRING

01 02
Roderick B. Johnson, an Since its origin, the Spring
Australian Framework has released
computer specialist
officially released the many versions 5.0 is the
Spring Framework in 2003 current Spring Framework
. version.
Advantages of
Spring Framework
1) Predefined Templates

Spring framework provides templates for JDBC, Hibernate, JPA etc.


technologies. So there is no need to write too much code. It hides the basic
steps of these technologies.

Let's take the example of JdbcTemplate, you don't need to write the code for
exception handling, creating connection, creating statement, committing
transaction, closing connection etc. We need to write the code of executing
query only. Thus, it save a lot of JDBC code.
2) Loose Coupling

• The Spring applications are loosely coupled because of


dependency injection.
The loose coupling

• One of the most key aspects of a Java project is loose coupling.


• The loose coupling in Java shows how to achieve loose coupling in Java projects or
programs. The more loosely coupled structures present in the project or program, the
better it is.
• In loose coupling, a method or class is almost independent, and they have less
depended on each other. In other words, the more knowledge one class or method has
about another class or method, the more tightly coupled structure is developed.
• If the classes or methods know less about each other, the more loosely coupled
structure comes into existence.
Example :

• If you change your shirt, then you are not forced to change
your body – when you can do that, then you have loose
coupling.
• When you can’t do that, then you have tight coupling.
3) Easy to test

The Dependency Injection makes easier


to test the application.

The EJB or Struts application


require server to run the
application but Spring framework
doesn't require server.
Spring framework is lightweight
because of its POJO implementation.

The Spring Framework doesn't force


4) Lightweight the programmer to inherit any class or
implement any interface.

That is why it is said non-invasive.


5) Fast
Development
• The Dependency Injection feature of
Spring Framework and it support to various
frameworks makes the easy development
of JavaEE application.
6) Powerful
abstraction

• It provides powerful
abstraction to JavaEE
specifications such
as JMS, JDBC, JPA
and JTA.
7) Declarative support

• It provides declarative support for caching, validation,


transactions and formatting.
Applications
of Spring
Applications of Spring

POJO Based - Spring enables developers to develop enterprise-class


applications using POJOs.

The benefit of using only POJOs is that you do not need an EJB container
product such as an application server but you have the option of using only a
robust servlet container such as Tomcat or some commercial product.
Applications of Spring

• Modular - Spring is organized in a modular fashion. Even


though the number of packages and classes are substantial,
you have to worry only about the ones you need and ignore
the rest.
Applications of Spring

Integration with existing frameworks - Spring does not reinvent the wheel, instead it truly makes
use of some of the existing technologies like several ORM frameworks, logging frameworks, JEE,
Quartz and JDK timers, and other view technologies.

Testablity - Testing an application written with Spring is simple because environment-dependent


code is moved into this framework. Furthermore, by using JavaBeanstyle POJOs, it becomes
easier to use dependency injection for injecting test data.
Applications of Spring

Web MVC - Spring's web framework is a well-designed web MVC


framework, which provides a great alternative to web frameworks such
as Struts or other over-engineered or less popular web frameworks.

Central Exception Handling - Spring provides a convenient API to


translate technology-specific exceptions (thrown by JDBC, Hibernate, or
JDO, for example) into consistent, unchecked exceptions.
Why do we use Spring in Java?

• Works on POJOs (Plain Old Java Object) which makes your application
lightweight.
• Provides predefined templates for JDBC, Hibernate, JPA etc., thus reducing
your effort of writing too much code.
• Because of dependency injection feature, your code becomes loosely coupled.
• Using Spring Framework, the development of Java Enterprise
Edition (JEE) applications became faster.
• It also provides strong abstraction to Java Enterprise Edition (JEE)
specifications.
What is the difference between Java and Spring?

Java Spring

Java is one of the prominent programming Spring is a Java-based open-source application


languages in the market. framework.

Spring Framework comes with various modules


Java provides a full-highlighted Enterprise
like Spring MVC, Spring Boot, Spring Security
Application Framework stack called Java EE for
which provides various ready to use features for
web application development
web application development.

Java EE is built upon a 3-D Architectural Spring is based on a layered architecture that
Framework which are Logical Tiers, Client Tiers consists of various modules that are built on top
and Presentation Tiers. of its core container.
Various projects undertaken by Spring.
Spring Framework Architecture

Spring Framework architecture is an arranged layered architecture


that consists of different modules. All the modules have their own
functionalities that are utilized to build an application.

There are around 20 modules that are generalized into Core


Container, Data Access/ Integration, Web, AOP (Aspect Oriented
Programming), Instrumentation, and Test.

Here, the developer is free to choose the required module. Its


modular architecture enables integration with other frameworks
without much hassle.
Spring Modules
Modules Of Spring Framework
Core Container

Spring Core: This module is the core of the Spring Framework. It provides an
implementation for features like IoC (Inversion of Control) and Dependency Injection with
a singleton design pattern.

Spring Bean: This module provides an implementation for the factory design pattern
through BeanFactory.

Spring Context: This module is built on the solid base provided by the Core and the
Beans modules and is a medium to access any object defined and configured.

Spring Expression Languages (SpEL): This module is an extension to expression


language supported by Java server pages. It provides a powerful expression language for
querying and manipulating an object graph, at runtime.
Spring Data Access/ Integration

JDBC: This module provides JDBC abstraction layer


which eliminates the need of repetitive and unnecessary
exception handling overhead.

ORM: ORM stands for Object Relational Mapping. This


module provides consistency/ portability to our code
regardless of data access technologies based on object
oriented mapping concept.
Spring Data Access/ Integration Cont

OXM: OXM stands for Object XML Mappers. It is used to convert the objects into XML
format and vice versa. The Spring OXM provides an uniform API to access any of
these OXM frameworks.

JMS: JMS stands for Java Messaging Service. This module contains features for
producing and consuming messages among various clients.

Transaction: This module supports programmatic and declarative transaction


management for classes that implement special interfaces and for all your POJOs. All
the enterprise level transaction implementation concepts can be implemented in
Spring by using this module.
Spring Web

Web: This module using servlet listeners and a web-oriented application context, provides basic web-
oriented integration features like multi-part file upload functionality and the initialization of the IoC
container.

Web-Servlet: This module contains Model-View-Controller (MVC) based implementation for web
applications. It provides all other features of MVC, including UI tags and data validations.

Web-Socket: This module provides support for WebSocket based and two-way communication
between the client and the server in web applications.

Web-Portlet: This module is also known as the Spring-MVC-Portlet module. It provides the support
for Spring-based Portlets and mirrors the functionality of a Web-Servlet module.
AOP language is
a powerful tool that allows
Aspect- developers to add enterprise
Oriented functionality to the application such
Programming as transaction, security etc.
(AOP)

It allows us to write less code and


separate the code logic. AOP
uses cross-cutting concerns.
Aspects

• The Aspects module


provides integration
with AspectJ, which is
again a powerful and
mature AOP
framework.
Instrumentation

• The Instrumentation module provides


class instrumentation support and class
loader implementations to be used in
certain application servers.
Messaging

• The Messaging module provides support for


STOMP as the WebSocket sub-protocol to use in
applications.
• It also supports an annotation
programming model for routing and
processing STOMP messages from
WebSocket clients.
Test

• The Test module supports the testing of


Spring components with JUnit or TestNG frameworks.
IRST SPRING

• https://netbeans.apache.org/kb/docs/web/quickstart-
webapps-spring.html
References

• https://sites.google.com/site/springmvcnetbeans/step-by-step/
• https://netbeans.apache.org/kb/docs/web/quickstart-
webapps-spring.html

You might also like