I'm studying spring beans and came across @Lookup, it says:
If we happen to decide to have a prototype Spring bean, then we are almost immediately faced with the problem of how will our singleton Spring beans access these prototype Spring beans?
hmm, I don't get it, because when I studied scope=prototype it says:
4.4.2 The prototype scope The non-singleton, prototype scope of bean deployment results in the creation of a new bean instance every time a request for that specific bean is made
so it seems i misinterpreted the words:
a request for that specific bean is made
actually programming in spring framework every line of the code is inside of some bean (i.e. @controller, @Service, etc), isn't it? And almost all of them are singletons, isn't it? So if I need prototype I just make scope=prototype and almost everytime it's injected to another bean (i.e. @controller, @Service, etc) isn't it?
So please give a real world scenarios, 1) when one should use @Lookup and 2) when it's not needed Ok for the 1) the scenario:
@Component
@Scope("prototype")
public class SchoolNotification {
// ... prototype-scoped state
}
@Component
public class StudentServices {
// ... member variables, etc.
@Lookup
public SchoolNotification getNotification() {
return null;
}
// ... getters and setters
}
Please, show me scenario for the 2) case, and explain please the difference Thank u
@Lookup
annotation, the way to actually inject the singleton bean involved some very confusing syntax that involved making the singleton class abstract. – Roddy of the Frozen Peas