Prototype creates a brand new instance everytime you call getBean on
the ApplicationContext. Whereas for Request, only one instance is
created for an HttpRequest. So in a single HttpRequest, I can call
getBean twice on Application and there will only ever be one bean
instantiated, whereas that same bean scoped to Prototype in that same
single HttpRequest would get 2 different instances.
HttpRequest scope
HttpRequest scope
Prototype scopeEmployee
employee1
= context.getBean("
employee
");
Employee
= context.getBean("
employee2
employee
");
==
employee1
; //This will return true
employee2
Employee
employee1
= context.getBean("
employee
");
Employee
= context.getBean("
employee2
employee
");
==
employee1
; //This will return false
employee2
No comments:
Post a Comment