SlideShare a Scribd company logo
Dependency Injection




     rgupta.trainer@gmail.com
Dependency Injection
•  Hello World DI
•  Using setter, Constructor Injection
•  Injecting Objects
•  Inner Beans, Aliases
•  Initializing Collections
•  Understanding Bean Scopes
•  Bean Autowiring
•  Using ApplicationContextAware
•  Bean Definition Inheritance
•  Lifecycle Callbacks
•  Method injections
•  Lookup method injection
• …
• …


                              rgupta.trainer@gmail.com
Introduction to DI




    rgupta.trainer@gmail.com
interface




Design as per interface




                          rgupta.trainer@gmail.com
Car depends on Wheel




                       rgupta.trainer@gmail.com
Most important :glue it all with XML




                       rgupta.trainer@gmail.com
DI ?
• DI is how objects or bean using Spring are brought together by container
  to accomplished the task

• It is AKA of IoC

• In most application and object is responsible for its own dependencies or
  associated objects and this is mostly achieved using JNDI

• In DI approach we allow container to manages dependencies of object
  creation and association


Hollywood ; don’t call me I will call you



                                rgupta.trainer@gmail.com
How Spring Work?




    rgupta.trainer@gmail.com
• Any object outside
  container get bean by
  providing ref

• We know object requiring
  bean contact to container ie
  Application context that
  refer SpringXML and create
  a Spring managed bean and
  that can be referred by
  requesting object
  outside/inside the
  container



                          rgupta.trainer@gmail.com
Spring Hello world example




         rgupta.trainer@gmail.com
rgupta.trainer@gmail.com
Setter injection….Ex




      rgupta.trainer@gmail.com
Injecting Objects




    rgupta.trainer@gmail.com
rgupta.trainer@gmail.com
Inner Beans
• Remove the definition of
  Point bean and put into
  triangle bean

• Remove the ref tag and put
  definition inside.

• No performance adv.

• whenever a bean is used for
  only one particular property,
  it’s advise to declare it as an
  inner bean
                               rgupta.trainer@gmail.com
Aliases

• alias giving name
  to same bean
• Use alias tag
• Now bean can be
  referred by new
  name


                      rgupta.trainer@gmail.com
Spring bean scopes

• In Spring, bean scope is used to decide which
  type of bean instance should be return from
  Spring container back to the caller.

• In most cases, you may only deal with the
  Spring’s core scope – singleton and prototype,
  and the default scope is singleton.


                   rgupta.trainer@gmail.com
Bean Scopes
           Scope                                    Description
          Singleton          (Default)Only one single instance will be
                             created

          Prototype          Creates any number of instances from a
                             single bean configuration

           Request           Scope of the bean instance will be limited to
                             the Request life cycle

           Session           Limited to session

        Global session       Limited to global session- Portlet context.


<bean name =“student” class =“Student” scope =“prototype”/>
                         rgupta.trainer@gmail.com
Singleton scope
ctx.getBean(“student”)




                            Spring
                           Container                Single student
                                                    instance




                         rgupta.trainer@gmail.com
Output in case of
default bean scope


                     rgupta.trainer@gmail.com
Prototype scope
ctx.getBean(“student”)




                            Spring
                           Container
                                                    Multiple Beans




                         rgupta.trainer@gmail.com
rgupta.trainer@gmail.com
Spring Collection
• What if member variable is collection
  major collection types are supported in
  Spring

  List – <list/>
  Set – <set/>
  Map – <map/>
  Properties – <props/>


              rgupta.trainer@gmail.com
Injecting list..




rgupta.trainer@gmail.com
rgupta.trainer@gmail.com
Auto Wiring

• Skip some of the configuration that we have
  to do by intelligent guessing what ref is
• AKA shortcut.
• Type of auto wiring
  – byName
  – byType (for only one composite object)
  – constructor


                    rgupta.trainer@gmail.com
<?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.xsd">


<bean id="tringle" class="com.ex3.code.Tringle" autowire="byName">

</bean>

<bean id="pointA" class="com.ex3.code.Point">
<property name="x" value="0"/>
<property name="y" value="0"/>
</bean>

<bean id="pointB" class="com.ex3.code.Point">
<property name="x" value="20"/>
<property name="y" value="0"/>
</bean>


<bean id="pointC" class="com.ex3.code.Point">
<property name="x" value="-20"/>
<property name="y" value="0"/>
</bean>


<alias name="tringle" alias="my-tringle"/>

</beans>



                                             rgupta.trainer@gmail.com
Aware interfaces..


• BeanName Aware interface
     • Want to know the name of bean configured
• ApplicationContextAware
     • Getting Application context
     • We need to implements ApplicationContextAware


     Container itself call setter related to aware interface
      before creation of any bean.

                        rgupta.trainer@gmail.com
Bean Definition Inheritance
• Lets say we have 100 bean definition in xml ,
  lets we have common definition in each bean
  definition aka template




                   rgupta.trainer@gmail.com
<?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.xsd">

<bean id="parenttringle" class="com.ex3.code.Tringle">
<property name="pointA" ref="firstPoint"></property>
</bean>


<bean id="tringle" class="com.ex3.code.Tringle" parent="parenttringle">
<property name="pointC" ref="secPoint"></property>
<property name="pointC" ref="thirdPoint"></property>
</bean>

<bean id="firstPoint" class="com.ex3.code.Point">
<property name="x" value="0"/>
<property name="y" value="0"/>
</bean>

<bean id="secPoint" class="com.ex3.code.Point">
<property name="x" value="20"/>
<property name="y" value="0"/>
</bean>


<bean id="thirdPoint" class="com.ex3.code.Point">
<property name="x" value="-20"/>
<property name="y" value="0"/>
</bean>


<alias name="tringle" alias="my-tringle"/>

</beans>




                                                     rgupta.trainer@gmail.com
Lifecycle Callbacks
• Spring provide us call-back method for life cycle
  of bean
           • for initialization of bean
           • for cleanup of bean


EX: Shut down hook
           • closing app context for SE applications
           • use class AbstractAppicationContext, when main finished

AbstractApplicationContext ctx=new ClassPathXmlApplicationContext("springWithAutoWiring.xml");
ctx.registerShutdownHook();



                                        rgupta.trainer@gmail.com
cofig init and destroyed method
• Choice I
            • implements InitializingBean,DisposableBean
• Choice II
            • Dont want to bind to spring interface interfaces......

<bean id="tringle" class="com.ex3.code.Tringle" autowire="byName" init-method="myInit" destroy-
    method="myDestroy">




What happens if both are there?
 first spring then my method is called.

                                          rgupta.trainer@gmail.com
public class Tringle implements
                                              public void setPointC(Point pointC) {
      InitializingBean,DisposableBean{        this.pointC = pointC;
                                              }
private Point pointA;                         public void draw() {
private Point pointB;                         System.out.println(pointA);
                                              System.out.println(pointB);
private Point pointC;                         System.out.println(pointC);
                                              }
public Point getPointA() {
                                              @Override
return pointA;                                public void afterPropertiesSet() throws Exception {
                                              // TODO Auto-generated method stub
}                                             System.out.println("called after init of bean");
public void setPointA(Point pointA) {         }
                                              @Override
this.pointA = pointA;                         public void destroy() throws Exception {
                                              System.out.println("called after destruction of bean");
}                                             }

public Point getPointB() {
                                              }
return pointB;                                }
}
public void setPointB(Point pointB) {
this.pointB = pointB;
}
public Point getPointC() {
return pointC;
}




                                         rgupta.trainer@gmail.com
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”/>
                             rgupta.trainer@gmail.com
Lookup Method Injection
public abstract class BookStore {                     public interface Book {
                                                      public String bookTitle();
public abstract Book orderBook();                     }
}
                                                                 Managed by Spring
 public class StoryBook implements Book{                 public class ProgrammingBook
 public String bookTitle() {                               implements Book{
 return "HarryPotter“; }                                 public String bookTitle() {
 }                                                       return "spring programming“; }
                                                         }



 • The ability of the container to override methods on
   container managed beans, to return the lookup
   result for another named bean in the container.

                                     rgupta.trainer@gmail.com
Thanks !!!




 rgupta.trainer@gmail.com

More Related Content

PDF
13 java beans
PPTX
Javascript Common Design Patterns
PDF
Scalable JavaScript Design Patterns
PDF
JavaScript Patterns
PDF
A Dexterity Intro for Recovering Archetypes Addicts
PDF
Javascript Design Patterns
PDF
Grain final border one
KEY
Overlays, Accordions & Tabs, Oh My
13 java beans
Javascript Common Design Patterns
Scalable JavaScript Design Patterns
JavaScript Patterns
A Dexterity Intro for Recovering Archetypes Addicts
Javascript Design Patterns
Grain final border one
Overlays, Accordions & Tabs, Oh My

What's hot (20)

PDF
파이썬 플라스크로 배우는 웹프로그래밍 #4 (ABCD)
PDF
Future-proofing Your JavaScript Apps (Compact edition)
PDF
Five class-based views everyone has written by now
PDF
Advanced GORM - Performance, Customization and Monitoring
PDF
JavaScript Libraries Overview
PDF
The Django Book, Chapter 16: django.contrib
PPTX
Powerful Generic Patterns With Django
PPTX
201204 random clustering
DOC
Cool Object Building With PHP
PPT
Spring
PPT
Spring talk111204
PPT
Patterns In-Javascript
PDF
JS Level Up: Prototypes
PPT
Introduction to hibernate
PDF
Play vs Rails
KEY
Attribute
PDF
JavaScript and UI Architecture Best Practices
PPTX
Developing components and extensions for ext js
PPTX
Javascript Design Patterns
PDF
Akka and the Zen of Reactive System Design
파이썬 플라스크로 배우는 웹프로그래밍 #4 (ABCD)
Future-proofing Your JavaScript Apps (Compact edition)
Five class-based views everyone has written by now
Advanced GORM - Performance, Customization and Monitoring
JavaScript Libraries Overview
The Django Book, Chapter 16: django.contrib
Powerful Generic Patterns With Django
201204 random clustering
Cool Object Building With PHP
Spring
Spring talk111204
Patterns In-Javascript
JS Level Up: Prototypes
Introduction to hibernate
Play vs Rails
Attribute
JavaScript and UI Architecture Best Practices
Developing components and extensions for ext js
Javascript Design Patterns
Akka and the Zen of Reactive System Design
Ad

Similar to Spring 3.0 dependancy injection (20)

PDF
Singletons in PHP - Why they are bad and how you can eliminate them from your...
PPT
SpringIntroductionpresentationoverintroduction.ppt
PPT
Spring Boot Introduction and framework.ppt
PPT
Spring talk111204
PDF
Using java beans(ii)
PPT
Spring framework
PDF
What's New in Enterprise JavaBean Technology ?
PDF
S314168 - What's New in Enterprise Java Bean Technology @ JavaOne Brazil 2010
PPTX
Session 4 - Understanding JAVA Beans.pptx
PPTX
Spring dependency injection
PPT
Story ofcorespring infodeck
PPTX
Spring framework IOC and Dependency Injection
PPT
Spring introduction
PDF
java beans
KEY
Objective C 基本介紹
PDF
Design patterns in Java - Monitis 2017
PDF
2-0. Spring ecosytem.pdf
PPTX
Test in action week 3
PPT
Spring Core
PPTX
Spring essentials 2 Spring Series 02)
Singletons in PHP - Why they are bad and how you can eliminate them from your...
SpringIntroductionpresentationoverintroduction.ppt
Spring Boot Introduction and framework.ppt
Spring talk111204
Using java beans(ii)
Spring framework
What's New in Enterprise JavaBean Technology ?
S314168 - What's New in Enterprise Java Bean Technology @ JavaOne Brazil 2010
Session 4 - Understanding JAVA Beans.pptx
Spring dependency injection
Story ofcorespring infodeck
Spring framework IOC and Dependency Injection
Spring introduction
java beans
Objective C 基本介紹
Design patterns in Java - Monitis 2017
2-0. Spring ecosytem.pdf
Test in action week 3
Spring Core
Spring essentials 2 Spring Series 02)
Ad

More from Rajiv Gupta (18)

PDF
Spring5 hibernate5 security5 lab step by step
PDF
GOF Design pattern with java
PPTX
1. java script language fundamentals
PDF
Introduction to jsf2
PDF
Hibernate 3
PDF
Weblogic 11g admin basic with screencast
PDF
Struts2
PDF
jsf2 Notes
PDF
Java 7
PDF
Struts2 notes
PDF
Lab work servlets and jsp
PPT
Java Servlet
PDF
Spring aop with aspect j
PDF
Java spring framework
TXT
Jsp Notes
PDF
Java Logging discussion Log4j,Slf4j
TXT
Advance C++notes
PDF
Core java 5 days workshop stuff
Spring5 hibernate5 security5 lab step by step
GOF Design pattern with java
1. java script language fundamentals
Introduction to jsf2
Hibernate 3
Weblogic 11g admin basic with screencast
Struts2
jsf2 Notes
Java 7
Struts2 notes
Lab work servlets and jsp
Java Servlet
Spring aop with aspect j
Java spring framework
Jsp Notes
Java Logging discussion Log4j,Slf4j
Advance C++notes
Core java 5 days workshop stuff

Recently uploaded (20)

PPTX
Cell Types and Its function , kingdom of life
PDF
Computing-Curriculum for Schools in Ghana
PPTX
Cell Structure & Organelles in detailed.
PPTX
master seminar digital applications in india
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
Pharma ospi slides which help in ospi learning
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
GDM (1) (1).pptx small presentation for students
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Classroom Observation Tools for Teachers
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Microbial disease of the cardiovascular and lymphatic systems
Cell Types and Its function , kingdom of life
Computing-Curriculum for Schools in Ghana
Cell Structure & Organelles in detailed.
master seminar digital applications in india
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
STATICS OF THE RIGID BODIES Hibbelers.pdf
Pharma ospi slides which help in ospi learning
102 student loan defaulters named and shamed – Is someone you know on the list?
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
GDM (1) (1).pptx small presentation for students
Module 4: Burden of Disease Tutorial Slides S2 2025
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Final Presentation General Medicine 03-08-2024.pptx
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Classroom Observation Tools for Teachers
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Microbial disease of the cardiovascular and lymphatic systems

Spring 3.0 dependancy injection

  • 1. Dependency Injection rgupta.trainer@gmail.com
  • 2. Dependency Injection • Hello World DI • Using setter, Constructor Injection • Injecting Objects • Inner Beans, Aliases • Initializing Collections • Understanding Bean Scopes • Bean Autowiring • Using ApplicationContextAware • Bean Definition Inheritance • Lifecycle Callbacks • Method injections • Lookup method injection • … • … rgupta.trainer@gmail.com
  • 3. Introduction to DI rgupta.trainer@gmail.com
  • 4. interface Design as per interface rgupta.trainer@gmail.com
  • 5. Car depends on Wheel rgupta.trainer@gmail.com
  • 6. Most important :glue it all with XML rgupta.trainer@gmail.com
  • 7. DI ? • DI is how objects or bean using Spring are brought together by container to accomplished the task • It is AKA of IoC • In most application and object is responsible for its own dependencies or associated objects and this is mostly achieved using JNDI • In DI approach we allow container to manages dependencies of object creation and association Hollywood ; don’t call me I will call you  rgupta.trainer@gmail.com
  • 8. How Spring Work? rgupta.trainer@gmail.com
  • 9. • Any object outside container get bean by providing ref • We know object requiring bean contact to container ie Application context that refer SpringXML and create a Spring managed bean and that can be referred by requesting object outside/inside the container rgupta.trainer@gmail.com
  • 10. Spring Hello world example rgupta.trainer@gmail.com
  • 12. Setter injection….Ex rgupta.trainer@gmail.com
  • 13. Injecting Objects rgupta.trainer@gmail.com
  • 15. Inner Beans • Remove the definition of Point bean and put into triangle bean • Remove the ref tag and put definition inside. • No performance adv. • whenever a bean is used for only one particular property, it’s advise to declare it as an inner bean rgupta.trainer@gmail.com
  • 16. Aliases • alias giving name to same bean • Use alias tag • Now bean can be referred by new name rgupta.trainer@gmail.com
  • 17. Spring bean scopes • In Spring, bean scope is used to decide which type of bean instance should be return from Spring container back to the caller. • In most cases, you may only deal with the Spring’s core scope – singleton and prototype, and the default scope is singleton. rgupta.trainer@gmail.com
  • 18. Bean Scopes Scope Description Singleton (Default)Only one single instance will be created Prototype Creates any number of instances from a single bean configuration Request Scope of the bean instance will be limited to the Request life cycle Session Limited to session Global session Limited to global session- Portlet context. <bean name =“student” class =“Student” scope =“prototype”/> rgupta.trainer@gmail.com
  • 19. Singleton scope ctx.getBean(“student”) Spring Container Single student instance rgupta.trainer@gmail.com
  • 20. Output in case of default bean scope rgupta.trainer@gmail.com
  • 21. Prototype scope ctx.getBean(“student”) Spring Container Multiple Beans rgupta.trainer@gmail.com
  • 23. Spring Collection • What if member variable is collection major collection types are supported in Spring List – <list/> Set – <set/> Map – <map/> Properties – <props/> rgupta.trainer@gmail.com
  • 26. Auto Wiring • Skip some of the configuration that we have to do by intelligent guessing what ref is • AKA shortcut. • Type of auto wiring – byName – byType (for only one composite object) – constructor rgupta.trainer@gmail.com
  • 27. <?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.xsd"> <bean id="tringle" class="com.ex3.code.Tringle" autowire="byName"> </bean> <bean id="pointA" class="com.ex3.code.Point"> <property name="x" value="0"/> <property name="y" value="0"/> </bean> <bean id="pointB" class="com.ex3.code.Point"> <property name="x" value="20"/> <property name="y" value="0"/> </bean> <bean id="pointC" class="com.ex3.code.Point"> <property name="x" value="-20"/> <property name="y" value="0"/> </bean> <alias name="tringle" alias="my-tringle"/> </beans> rgupta.trainer@gmail.com
  • 28. Aware interfaces.. • BeanName Aware interface • Want to know the name of bean configured • ApplicationContextAware • Getting Application context • We need to implements ApplicationContextAware Container itself call setter related to aware interface before creation of any bean. rgupta.trainer@gmail.com
  • 29. Bean Definition Inheritance • Lets say we have 100 bean definition in xml , lets we have common definition in each bean definition aka template rgupta.trainer@gmail.com
  • 30. <?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.xsd"> <bean id="parenttringle" class="com.ex3.code.Tringle"> <property name="pointA" ref="firstPoint"></property> </bean> <bean id="tringle" class="com.ex3.code.Tringle" parent="parenttringle"> <property name="pointC" ref="secPoint"></property> <property name="pointC" ref="thirdPoint"></property> </bean> <bean id="firstPoint" class="com.ex3.code.Point"> <property name="x" value="0"/> <property name="y" value="0"/> </bean> <bean id="secPoint" class="com.ex3.code.Point"> <property name="x" value="20"/> <property name="y" value="0"/> </bean> <bean id="thirdPoint" class="com.ex3.code.Point"> <property name="x" value="-20"/> <property name="y" value="0"/> </bean> <alias name="tringle" alias="my-tringle"/> </beans> rgupta.trainer@gmail.com
  • 31. Lifecycle Callbacks • Spring provide us call-back method for life cycle of bean • for initialization of bean • for cleanup of bean EX: Shut down hook • closing app context for SE applications • use class AbstractAppicationContext, when main finished AbstractApplicationContext ctx=new ClassPathXmlApplicationContext("springWithAutoWiring.xml"); ctx.registerShutdownHook(); rgupta.trainer@gmail.com
  • 32. cofig init and destroyed method • Choice I • implements InitializingBean,DisposableBean • Choice II • Dont want to bind to spring interface interfaces...... <bean id="tringle" class="com.ex3.code.Tringle" autowire="byName" init-method="myInit" destroy- method="myDestroy"> What happens if both are there? first spring then my method is called. rgupta.trainer@gmail.com
  • 33. public class Tringle implements public void setPointC(Point pointC) { InitializingBean,DisposableBean{ this.pointC = pointC; } private Point pointA; public void draw() { private Point pointB; System.out.println(pointA); System.out.println(pointB); private Point pointC; System.out.println(pointC); } public Point getPointA() { @Override return pointA; public void afterPropertiesSet() throws Exception { // TODO Auto-generated method stub } System.out.println("called after init of bean"); public void setPointA(Point pointA) { } @Override this.pointA = pointA; public void destroy() throws Exception { System.out.println("called after destruction of bean"); } } public Point getPointB() { } return pointB; } } public void setPointB(Point pointB) { this.pointB = pointB; } public Point getPointC() { return pointC; } rgupta.trainer@gmail.com
  • 34. 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”/> rgupta.trainer@gmail.com
  • 35. Lookup Method Injection public abstract class BookStore { public interface Book { public String bookTitle(); public abstract Book orderBook(); } } Managed by Spring public class StoryBook implements Book{ public class ProgrammingBook public String bookTitle() { implements Book{ return "HarryPotter“; } public String bookTitle() { } return "spring programming“; } } • The ability of the container to override methods on container managed beans, to return the lookup result for another named bean in the container. rgupta.trainer@gmail.com