Spring @LookUp Annotation Example
![Image](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhSFr9G8OTwo2aDZv94s2fejFAFNpbXx4VDi8tCcn8hshRG4fdR2MP4_0hvq8A7KmOmGczTGmqTWPN9co7EkyfTuxBO4UT23Ny85v0Iv-XHmx9K1IjEeAfWsvIrI9ipTXjGEa9Ya2HUfTkjIdm4NpEFzS1e3qPvKqGyvMuRFBbXVUZW8olMYWtI1LJ8cQ/w400-h185/lookup.png)
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