I know in servlets many scopes(request, session....).
I don't want directly use HttpRequest and HttpResponse.
• Singleton: This scopes the bean definition to a single instance per Spring IoC container (default).
• Prototype: This scopes a single bean definition to have any number of object instances.
Message aMessage; //object
// singleton bean scope
aMessageA = new Message();
aMessageA = (Message) applicationContext.getBean("message");
aMessageA.setText("message1 :D");
System.out.println(aMessageA.getText());
aMessageB = new Message();
aMessageB = (Message) applicationContext.getBean("message");
System.out.println(aMessageB.getText());
// result will be the same for both objects because it's just one instance.
// Prototype bean scope. scope="prototype"
aMessageA = new Message();
aMessageA = (Message) applicationContext.getBean("message");
aMessageA.setText("message :D");
System.out.println(aMessageA.getText());
aMessageB = new Message();
aMessageB = (Message) applicationContext.getBean("message");
System.out.println(aMessageB.getText());
/* first object will print the message, but the second one won't because it's a new instance.*/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With