Square CSS

Sunday, May 24, 2020

@Lookup : Annotation In Spring




Introduction :


@Lookup tells spring to return the instance of the return type of method.
In other words whatever be the return type of method, it's instance will be returned.

Use case :


In situations where a prototype bean needs to be injected in a singleton @Autowired won't work.
In such situations @Lookup is helpful.

Example :


Suppose we have a prototype bean shown below.



@Component @Scope("Prototype")
public class CheckPrototype{
//Some Code }
   




If we want above bean in some singleton class then instead of @Autowired the below code will work.



@Lookup//to handle prototype in singleton public CheckPrototype getCheckPrototype() { // return new Instance }
     

Limitations :


1. @Lookup won't work for static, final and private fields
2. @Lookup wont work if the bean class is final.

No comments:

Post a Comment

Some Algorithms

Algorithm: Tower of Hanoi

Tower of Hanoi consists of three towers called as pegs with n number of rings. Rings are of different size.  Conditions to be fulfill...

Popular Posts