Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
20 views

Spring Bean Scope Method Injection

The document discusses different Spring bean scopes like singleton, prototype, request, and session scope and how they determine if single or multiple bean instances are created. It also covers method injection and lookup method injection where Spring can override methods on beans and return other named beans from the container. The key concepts are how bean scopes control instance creation and how method and lookup method injection allow Spring to modify bean method behavior.

Uploaded by

govindbirajdar
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPSX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Spring Bean Scope Method Injection

The document discusses different Spring bean scopes like singleton, prototype, request, and session scope and how they determine if single or multiple bean instances are created. It also covers method injection and lookup method injection where Spring can override methods on beans and return other named beans from the container. The key concepts are how bean scopes control instance creation and how method and lookup method injection allow Spring to modify bean method behavior.

Uploaded by

govindbirajdar
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPSX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Spring Bean Scope and Method Injection

www.java9s.com

Bean Scopes
Description (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 <bean name =student class =Student scope =prototype/> Global session Limited to global Scope Singleton

Singleton scope
ctx.getBean( student)

Spring Containe r

Single student instance

Prototype scope
ctx.getBean( student)

Spring Containe r

Multiple Bean

Method Injection Method


Replace

class MobileStore{ public String buyMobile() { return "Bought a Mobile Phone"; obileStoreReplacer implements MethodReplacer{ }} ic Object reimplement(Objectobj, Methodmethod, Object hrows Throwable{ rn Bought an iPhone;

obileStore class =MobileStore> e-method name =buyMobile replacer =mobileStor

obileStoreReplacer class =MobileStoreReplacer/>

Lookup Method Injection

ublic abstract class BookStorepublic interface Book { { public String bookTitle(); ublic abstract Book orderBook(); }
public class StoryBook implements Book{ public String bookTitle() { return "HarryPotter; } } public class ProgrammingBook implements Book{ public String bookTitle() { return "spring programming; } }

Managed by Spring

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

You might also like