The document discusses Spring, a popular Java application framework. It provides definitions and explanations of key Spring concepts like frameworks, dependency injection, and the Spring application context. It describes the modular architecture of Spring, including core modules for aspects like data access, web, and AOP. It also compares Spring to Hibernate, explaining that Spring is a framework that helps follow MVC architecture while Hibernate provides object-relational mapping.
2. What is a framework?
Framework is a collection of classes of predefined code to which
can use in your program to solve some problems.
Advantages of java framework:
Efficiency
Security
Expense
Support
3. Disadvantages of java framework:
Restriction-we cannot modify the API
Code is public-The framework is readily available to
everyone.
Custom built feature
4. Difference between java framework and SPRING
Spring framework-will increase the efficiency of the application and will
reduce overall application development time. So we can easily develop our
project within the given time framework.
What are advantages of SPRING framework?
Powerful open source
Light weight application framework.
Reduces overall complexities.
It is framework of frameworks.
We can integrate hibernate code with spring code
5. SPRING was first released on February
2003 by Rod Johnson
Why spring is so popular?
It is the distinct division between java beans models, controllers
and view.(Spring is basically an MVC architecture)
Spring MVC is very flexible as it make use of interfaces.
*no restriction come over here.
*we can use our implementation as per our requirement.
6. Spring is a:
Application framework.
Light weighted.
Layered architecture.
Loose coupling(less dependency of one module to another module)
Easy integration with ORM technologies(we can integrate hibernate)
7. What is the difference between spring and hibernate?
Spring and Hibernate are two different things, Spring has several components
like Dependency Injection, Spring MVC, Spring ORM, Spring Rest API.
So Spring ORM and Hibernate are kind of similar, they both deal with the
object relation model, which means they deal with connection java objects to
data base entities.
Loose coupling-The dependent objects are written outside your java code so
if you need to change the dependent object you just need to change it in one
location(xml configuration file).
Hibernate- It provides with ORM where in you are able to perform database
transaction is the form of objects mapped to corresponding table, using
configuration xml files.
Spring, on the other hand is a framework that helps you follow the MVC
architecture in an effective and efficient way.
9. The Spring framework is a layered architecture which consists of several
modules.
All modules are built on the top of its core container.
These modules provide everything that a developer may need for use in
the enterprise application development.
He is always free to choose what features he needs and eliminate the
modules which are of no use.
It's modular architecture enables integration with other frameworks.
10. Spring Architecture continues….
The Core Module: Provides the Dependency Injection (DI) feature which is the
basic concept of the Spring framework. This module contains the BeanFactory, an
implementation of Factory Pattern which creates the bean as per the configurations
provided by the developer in an XML file. Core Container
Core: provides the fundamental parts of Spring framework.
Bean: It’s an object. Provides Bean Factory.
BeanFactory, an implementation of Factory Pattern which creates the bean
as per the configurations provided by the developer in an XML file
Context: It's a medium to access any objects defined and configured.
SpEL-Spring Expression Language:it provides a powerful expression
language.
11. Data access
JDBC:provides a jdbc abstraction layer.
ORM:provides integration layers for popular object-relational
mapping API’s.
OXM: Object XML Mapping. Provides an abstraction layer.
JMS(Java Message Service):contains features for producing and
consuming messages.
Transactions:support programmatic and declarative transaction
management.
12. Web Module: Spring comes with MVC framework which eases
the task of developing web applications. It also integrates well with the
most popular MVC frameworks like Struts, JSF, etc.
Web Socket:provide support for web socket based a two way
communication between client and server.
Servlet:it is the core part of enterprise edition.Contains Spring
MVC implementation for web application.
Web:provide basic web-oriented integration features.
Portlet: provides MVC implementation. It is a stand alone
application.
13. Miscellaneous
AOP: provides an Aspect-Oriented Programming
implementation. It aims at declarative transaction management
which is easier to maintain.
Aspects: provides integration with aspects.
Instrumentation:provides class instrumentation support and
class loader implementations.
Messaging:provide support for messaging.
Test:support Support the testing of spring components(unit
testing)
14. Spring IoC Containers
The Spring container is at the core of the Spring Framework.
The container will create the objects, wire them together, configure them,
and manage their complete life cycle from creation till destruction.
The Spring container uses DI(Dependency Injection) to manage the
components that make up an application. (Dependency injection-Just direct object
its dependent object and container will bind them at runtime)
Dependency Injection (DI) is a design pattern that removes the
dependency from the programming code so that it can be easy to
manage and test the application. Dependency Injection makes our
programming code loosely coupled
15. Spring provides the following two distinct types of containers.
Spring BeanFactory Container
This is the simplest container and is defined by
the org.springframework.beans.factory.BeanFactory interface.
Spring ApplicationContext Container
This container adds more enterprise-specific functionality.
This container is defined by
the org.springframework.context.ApplicationContext interface.
16. The ApplicationContext container includes all functionality of
the BeanFactorycontainer, so it is generally recommended
over BeanFactory.
BeanFactory can still be used for lightweight applications like mobile
devices or applet-based applications where data volume and speed is
significant.
17. BEAN SCOPE &METHOD INJECTION
Spring Bean Definition: The objects that form the backbone of your
application and that are managed by the Spring IoC container are called beans.
A bean is an object that is instantiated, assembled, and otherwise managed by a
Spring IoC container.
When defining a <bean> you have the option of declaring a scope for that bean.
18. The Spring Framework supports the following five scopes
Singleton-Only one singleton instance will be created(default)
Prototype-Creates any number of instance from a single bean configuration.
Below three are connected with web based application Only valid in the
context of a web-aware Spring ApplicationContext
Request- This scopes a bean definition to an HTTP request.
Session-This scopes a bean definition to an HTTP session.
Global Session-This scopes a bean definition to a global HTTP session.
<bean name=“student” class=“Student” scope=“prototype”/>
19. Singleton Scope
Default scope-if we don’t define anything in scope spring construct
automatically to Singleton Scope
With this what does it mean that, even though you call an instance of the
bean using spring framework for one or more times all the time only one
instance will return.
Single student
instance
ctx.getBean(“student”)
Spring
Container
21. Method Injection-Method Replace
class MobileStore
{
public String buyMobile()
{
return “Bought a Mobile
Phone”;
}
}
class MobileStoreReplacer implements
MethodReplacer
{
public Object reimplement(Object
obj,Method method,Object[]args)
throws Throwable
{
return “Bought an iPhone”;
}
}
<bean id=“mobileStore” class “MobileStore”>
<replace-method name=“buyMobile”
replacer=“mobileStoreReplacer”/></bean>
<bean id=“mobileStoreReplacer” class
“MobileStoreReplacer”/>
22. On run time when ever you get a bean of mobile Store through
spring framework and call buyMobile.Spring understands it
need to replace buyMobile to MobileStoreReplacer.
23.
24.
25.
26. Spring - Bean Definition Inheritance
A bean definition can contain a lot of configuration information, including
constructor arguments, property values and so on.
Spring Bean definition inheritance has nothing to do with Java class
inheritance but the inheritance concept is same.
Following is the configuration file Beans.xml where we defined "helloWorld"
bean which has two properties message1 and message2. Next "helloIndia"
bean has been defined as a child of "helloWorld" bean by using parent
attribute. The child bean inherits message2 property as is, and overrides
message1 property and introduces one more property message3.
27. Beans.xml
<?xml version = "1.0" encoding = "UTF-8"?>
<bean id = "helloWorld" class = "com.tutorialspoint.HelloWorld">
<property name = "message1" value = "Hello World!"/>
<property name = "message2" value = "Hello Second World!"/>
</bean>
<bean id ="helloIndia" class = "com.tutorialspoint.HelloIndia"
parent = "helloWorld">
<property name = "message1" value = "Hello India!"/>
<property name = "message3" value = "Namaste India!"/>
</bean> </beans>
28. HelloWorld.java
public class HelloWorld
{ private String message1;
private String message2;
public void setMessage1(String message)
{
this.message1 = message;
}
public void setMessage2(String message)
{
this.message2 = message;
}
public void getMessage1()
{ System.out.println("World Message1 : " + message1);
}
public void getMessage2()
{
System.out.println("World Message2 : " + message2);} }
29. HelloIndia.java
public class HelloIndia
{
private String message1;
private String message2;
private String message3;
public void setMessage1(String message)
{
this.message1 = message;
}
public void setMessage2(String message)
{
this.message2 = message;
}
public void setMessage3(String message)
{ this.message3 = message; } public void getMessage1(){ System.out.println
("India Message1 : " + message1);
} public void getMessage2(){ System.out.println("India Message2 : " + message2);
} public void getMessage3(){ System.out.println("India Message3 : " + message3); } }
31. output
World Message1 : Hello World!
World Message2 : Hello Second World!
India Message1 : Hello India!
India Message2 : Hello Second World!
India Message3 : Namaste India!