I'd like to use Spring's "dependency injections" to associate my View object with a helper object. Unfortunately, I need to construct a new helper object for each request and right now Spring's make me share one.
I configure my view to use the helper object in the bean XML. The view is associated with the controller via the standard XmlViewResolver. The controller, view, and helper object are defined as not singleton.
I know the object is shared because when it's invoked, it writes to an output stream that's been set. Under jmeter load testing, I find the response has already been written - the result of two views trying to share the same helper object and their output streams getting mismatched.
Any advice would be appreciated!
-
Unshared Object in Spring Framework (3 messages)
- Posted by: Luke Samaha
- Posted on: December 28 2004 13:17 EST
Threaded Messages (3)
- change the bean declaration by Benjamin Possolo on December 28 2004 14:19 EST
- Not Singleton by Luke Samaha on December 28 2004 14:52 EST
- Not Singleton by Luke Samaha on December 28 2004 02:54 EST
- Not Singleton by Luke Samaha on December 28 2004 14:52 EST
-
change the bean declaration[ Go to top ]
- Posted by: Benjamin Possolo
- Posted on: December 28 2004 14:19 EST
- in response to Luke Samaha
in the applicationContext.xml file (or whatever alternative file name u use instead) in each bean definition u can set the singleton attribute to "false"
<bean id="exampleBean" class="examples.exampleBean" singleton="false"/>
now each time u refer to 'exampleBean' in the web application context it creates a new instance of that class and returns it instead (its called a 'prototype' in Spring language...although many dislike this term in this context).
look it up in section 3.2.5 in the spring reference pdf. -
Not Singleton[ Go to top ]
- Posted by: Luke Samaha
- Posted on: December 28 2004 14:52 EST
- in response to Benjamin Possolo
Sorry for any confusion, I tried to be clear the beans are marked as singleton.
> The controller, view, and helper object are defined
> as not singleton.
Note that these entities are not created using an ApplicationContext or BeanFactory (which would respond as you describe), but rather by the Spring Framework when it associates the request with a controller and a view. -
Not Singleton[ Go to top ]
- Posted by: Luke Samaha
- Posted on: December 28 2004 14:54 EST
- in response to Luke Samaha
Correction to above - "are marked as NOT singleton". Example:<bean id="InboxController" class="myco.wfds.web.gondola.InboxController" singleton="false"/>