Reputation: 37034
I know in servlets many scopes(request, session....).
I don't want directly use HttpRequest
and HttpResponse
.
Upvotes: 3
Views: 4377
Reputation: 2394
Spring MVC offers more scopes like request, session, global session.
You can annotate spring beans to use correct scope. Please follow below link to find more.
http://static.springsource.org/spring/docs/2.0.x/reference/beans.html#beans-factory-scopes
Upvotes: 0
Reputation: 131
You can configure the scope of a bean you wire up in your configuration
Example configuration:
<bean id="bean-id-name" class="abc.xyz.classname" scope="singleton">
Reference on spring bean scopes: http://static.springsource.org/spring/docs/3.2.4.RELEASE/spring-framework-reference/html/beans.html#beans-factory-scopes
Upvotes: 0
Reputation: 1559
• 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.*/
Upvotes: 1