Showing posts with the label @LookUp

Spring @LookUp Annotation Example

In this section we will learn about @LookUp  Annotation. How to use @Lookup annotation By default, the scope of the bean in a Spring application are singletons , and we use a constructor or setter to implement dependencies.  But there is another situation: there is a singleton u ser , and he needs a new role bean every time. That is, User is a singleton bean, and Role is prototype bean. The life cycles of beans are different. Bean User is created by the container only once, and bean Role is created every time a new one is created – let's say this happens every time you call some method of the User bean. This is where the introduction of a bean using the @ Lookup method comes in handy. It occurs not when the container is initialized, but later, each time the method is called. A method annotated with @Lookup tells Spring to return an instance of the method's return type when we invoke it. What is Lookup method injection? We create a stub method( createRole ) in the User bean and