Spring bean scope and method injection
This presentation is the property of its rightful owner.
Sponsored Links
1 / 6

Spring Bean Scope and Method Injection PowerPoint PPT Presentation


  • 77 Views
  • Uploaded on
  • Presentation posted in: General

Spring Bean Scope and Method Injection. www.java9s.com. Bean Scopes. <bean name =“student” class =“Student” scope =“prototype” />. Singleton scope. ctx.getBean(“student”). Spring Container. Single student instance. Prototype scope. ctx.getBean(“student”). Spring Container.

Download Presentation

Spring Bean Scope and Method Injection

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Spring bean scope and method injection

Spring Bean Scope and Method Injection

www.java9s.com


Bean scopes

Bean Scopes

<bean name =“student” class =“Student” scope =“prototype”/>


Singleton scope

Singleton scope

ctx.getBean(“student”)

Spring Container

Single student

instance


Prototype scope

Prototype scope

ctx.getBean(“student”)

Spring Container

Multiple Beans


Method injection method replace

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”/>


Lookup method injection

Lookup Method Injection

public abstract class BookStore {

public abstract Book orderBook();

}

public interface Book {

public String bookTitle();

}

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

Managed by Spring

public class StoryBook implements Book{

public String bookTitle() {

return "HarryPotter“; }

}

public class ProgrammingBook

implements Book{

public String bookTitle() {

return "spring programming“; }

}


  • Login