Spring
in
PracticeVersion 4.0
[ Overview | Design | Architecture | DI & IoC ]
By: SAURABH SHARMA | TechShareZone Community
Source: http://javazone.techsharezone.com | +91 810 591 1711
Session: 1
 Created by Rod Jhonson
 An open source framework
 Spring is an light weight Dependency Injection and Aspect
Oriented Container and framework.
- Spring Overview
- Spring framework architecture
- Deprecated Methods and Packages
- Java 8 Support
- Groovy Bean Definition DSL
- Spring Core Changes
- Spring Web Module Features
Currently Spring 4.2 is the latest version and they have
enhanced event listener, hibernate, jetty and modern Java
component design with spring framework.
- Spring 4.0 Release and Features
 Dependency Injection
 Also known as IoC (Inversion of Control)
 Aspect Oriented Programming
 Runtime injection-based
 Portable Service Abstractions
 The rest of spring
 ORM, DAO, Web MVC, Web, etc.
 Allows access to these without knowing how they actually
work
- What does Spring offer?
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.
Constructor-based dependency injection
Constructor-based DI is accomplished when the container invokes a class constructor
with a number of arguments, each representing a dependency on other class.
Setter-based dependency injection
Setter-based DI is accomplished by the container calling setter methods on your
beans after invoking a no-argument constructor or no-argument static factory
method to instantiate your bean.
- Dependency Injection in Spring
- IoC is all about Object dependencies.
- Traditional "Pull" approach:
- Direct instantiation
- Looking up a service via JNDI
"Push" approach:
- Something outside of the Object "pushes" its
dependencies into it.
The Object has no knowledge of how it gets its dependencies, it
just assumes they are there.
- The "Push" approach is called "Dependency Injection".
- What is Inversion of Control (IoC)?
 Typical java bean with a unique id
 Beans are normally created by Spring as late as possible
- What is a bean?
Scope Description
Singleton Single instance spring IoC
Prototype Single bean definition to have any number of object instance
Request A bean definition to an HTTP request. Only valid in the context of a web
aware spring applicationContext.
Session A bean definition to an HTTP session. Only valid in the context of a web
aware spring applicationContext.
Global-session A bean definition to an global HTTP session. Only valid in the context of a
web aware spring applicationContext.
 Defines a bean for Spring to manage
 Key attributes
 class (required): fully qualified java class name
 id: the unique identifier for this bean
 configuration: (singleton, init-method, etc.)
 constructor-arg: arguments to pass to the constructor at creation
time
 property: arguments to pass to the bean setters at creation time
 Collaborators: other beans needed in this bean (a.k.a
dependencies), specified in property or constructor-arg
 Typically defined in an XML file
- What is a bean definition?
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd">
<bean id="expense" class="com.tsz.springfactory.model.Expense" scope="singleton“
init-method=“init” destroy-method=“destroy”>
</bean>
</beans>
- Sample bean definition
Thank You
“This recepie may not be tasty but it was full of
ingredients of knowledge”

Spring overview &amp; architecture

  • 1.
    Spring in PracticeVersion 4.0 [ Overview| Design | Architecture | DI & IoC ] By: SAURABH SHARMA | TechShareZone Community Source: http://javazone.techsharezone.com | +91 810 591 1711 Session: 1
  • 2.
     Created byRod Jhonson  An open source framework  Spring is an light weight Dependency Injection and Aspect Oriented Container and framework. - Spring Overview
  • 3.
    - Spring frameworkarchitecture
  • 4.
    - Deprecated Methodsand Packages - Java 8 Support - Groovy Bean Definition DSL - Spring Core Changes - Spring Web Module Features Currently Spring 4.2 is the latest version and they have enhanced event listener, hibernate, jetty and modern Java component design with spring framework. - Spring 4.0 Release and Features
  • 5.
     Dependency Injection Also known as IoC (Inversion of Control)  Aspect Oriented Programming  Runtime injection-based  Portable Service Abstractions  The rest of spring  ORM, DAO, Web MVC, Web, etc.  Allows access to these without knowing how they actually work - What does Spring offer?
  • 6.
    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. Constructor-based dependency injection Constructor-based DI is accomplished when the container invokes a class constructor with a number of arguments, each representing a dependency on other class. Setter-based dependency injection Setter-based DI is accomplished by the container calling setter methods on your beans after invoking a no-argument constructor or no-argument static factory method to instantiate your bean. - Dependency Injection in Spring
  • 7.
    - IoC isall about Object dependencies. - Traditional "Pull" approach: - Direct instantiation - Looking up a service via JNDI "Push" approach: - Something outside of the Object "pushes" its dependencies into it. The Object has no knowledge of how it gets its dependencies, it just assumes they are there. - The "Push" approach is called "Dependency Injection". - What is Inversion of Control (IoC)?
  • 8.
     Typical javabean with a unique id  Beans are normally created by Spring as late as possible - What is a bean? Scope Description Singleton Single instance spring IoC Prototype Single bean definition to have any number of object instance Request A bean definition to an HTTP request. Only valid in the context of a web aware spring applicationContext. Session A bean definition to an HTTP session. Only valid in the context of a web aware spring applicationContext. Global-session A bean definition to an global HTTP session. Only valid in the context of a web aware spring applicationContext.
  • 9.
     Defines abean for Spring to manage  Key attributes  class (required): fully qualified java class name  id: the unique identifier for this bean  configuration: (singleton, init-method, etc.)  constructor-arg: arguments to pass to the constructor at creation time  property: arguments to pass to the bean setters at creation time  Collaborators: other beans needed in this bean (a.k.a dependencies), specified in property or constructor-arg  Typically defined in an XML file - What is a bean definition?
  • 10.
    <?xml version="1.0" encoding="UTF-8"?> <beansxmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd"> <bean id="expense" class="com.tsz.springfactory.model.Expense" scope="singleton“ init-method=“init” destroy-method=“destroy”> </bean> </beans> - Sample bean definition
  • 11.
    Thank You “This recepiemay not be tasty but it was full of ingredients of knowledge”