Spring Boot
·
Spring is the most popular application
development framework for enterprise Java. Spring Framework creates high performing, easily
testable, and reusable code.
·
Spring is lightweight when it comes to size and
transparency. The basic version of Spring framework is around 2MB
·
Spring framework targets to make J2EE development
easier to use and promotes good programming practices by enabling a POJO-based
programming model. (POJO - Plain Old Java Object).
Benefits of Using the
Spring Framework
Following is the list of few of the great
benefits of using Spring Framework −
·
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.
·
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.
·
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.
·
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.
·
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.
·
Spring provides a
convenient API to translate technology-specific exceptions (thrown by JDBC,
Hibernate, or JDO, for example) into consistent, unchecked exceptions.
·
Lightweight IoC
containers tend to be lightweight, especially when compared to EJB containers,
for example. This is beneficial for developing and deploying applications on
computers with limited memory and CPU resources.
·
Spring provides a consistent
transaction management interface that can scale down to a local transaction
(using a single database, for example) and scale up to global transactions
(using JTA, for example).
Dependency Injection
(DI) - Let's
look at these two words separately. Here the dependency part translates into an
association between two classes. For example, class A is dependent of class B.
Now, let's look at the second part, injection. All this means is, class B will
get injected into class A by the Inversion
of Control (IoC).
The Inversion of Control (IoC) is a general
concept, and it can be expressed in many different ways. Dependency Injection
is merely one concrete example of Inversion of Control.
Aspect Oriented
Programming (AOP) - The
functions that span multiple points of an application are called cross-cutting concerns and these
cross-cutting concerns are conceptually separate from the application's
business logic. There are various common good examples of aspects including
logging, declarative transactions, security, caching, etc.
However, Spring is modular, allowing you to pick
and choose which modules are applicable to you, without having to bring in the
rest. The Spring Framework provides about 20 modules which can be used based on
an application requirement.
Data Access/Integration
·
The JDBC module
provides a JDBC-abstraction layer that removes the need for tedious JDBC
related coding.
·
The ORM module
provides integration layers for popular object-relational mapping APIs,
including JPA, JDO, Hibernate, and iBatis.
·
The OXM module
provides an abstraction layer that supports Object/XML mapping implementations for
JAXB, Castor, XMLBeans, JiBX and XStream.
·
The Java Messaging
Service JMS module contains features for producing and
consuming messages.
·
The Transaction module
supports programmatic and declarative transaction management for classes that
implement special interfaces and for all your POJOs.
Web
·
The Web module
provides basic web-oriented integration features such as multipart file-upload
functionality and the initialization of the IoC container using servlet
listeners and a web-oriented application context.
·
The Web-MVC module
contains Spring's Model-View-Controller (MVC) implementation for web
applications.
·
The Web-Socket module
provides support for WebSocket-based, two-way communication between the client
and the server in web applications.
·
The Web-Portlet module
provides the MVC implementation to be used in a portlet environment and mirrors
the functionality of Web-Servlet module.
Miscellaneous
·
The AOP module
provides an aspect-oriented programming implementation allowing you to define
method-interceptors and point cuts to cleanly decouple code that implements
functionality that should be separated.
·
The Aspects module
provides integration with AspectJ, which is again a powerful and mature AOP
framework.
·
The Instrumentation module
provides class instrumentation support and class loader implementations to be
used in certain application servers.
·
The Messaging module
provides support for STOMP as the Web Socket sub-protocol to use in
applications. It also supports an annotation programming model for routing and
processing STOMP messages from Web Socket clients.
·
The Test module
supports the testing of Spring components with JUnit or TestNG frameworks.
Core Container
·
The Core module
provides the fundamental parts of the framework, including the IoC and
Dependency Injection features.
·
The Bean module
provides Bean Factory, which is a sophisticated implementation of the factory
pattern.
·
The Context module
builds on the solid base provided by the Core and Beans modules and it is a
medium to access any objects defined and configured. The Application Context
interface is the focal point of the Context module.
·
The SpEL module
provides a powerful expression language for querying and manipulating an object
graph at runtime.
Code Ex :
Here is the content of HelloWorld.java file
−
package com.tutorialspoint;
public class HelloWorld {
private String message;
public void setMessage(String message){
this.message = message;
}
public void getMessage(){
System.out.println("Your Message : " + message);
}
}
Following is the content of the second file MainApp.java −
package com.tutorialspoint;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class MainApp {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml");
HelloWorld obj = (HelloWorld) context.getBean("helloWorld");
obj.getMessage();
}
}



Comments
Post a Comment