spring bean scope and method injection
Download
Skip this Video
Download Presentation
Spring Bean Scope and Method Injection

Loading in 2 Seconds...

play fullscreen
1 / 6

Spring Bean Scope and Method Injection - PowerPoint PPT Presentation


  • 105 Views
  • Uploaded on

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.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Spring Bean Scope and Method Injection' - baird


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
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“; }

}

ad