1 / 6

Spring Bean Scope and Method Injection

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.

baird
Télécharger la présentation

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Spring Bean Scope and Method Injection www.java9s.com

  2. Bean Scopes <bean name =“student” class =“Student” scope =“prototype”/>

  3. Singleton scope ctx.getBean(“student”) Spring Container Single student instance

  4. Prototype scope ctx.getBean(“student”) Spring Container Multiple Beans

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

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

More Related