Hello!
Could simplify the problem.
We can say that I have only one applicationContext-j2ee.xml.
Here I have the following bean:
<bean id="image" class="com.myown.ImageImpl">
<property name="imageHandler" ref="imageHandler" />
<property name="searchHandler" ref="searchHandler" />
<property name="searchBuilder" ref="searchBuilder" />
</bean>
<bean id="imageHandler"
class="com.myown.ImageHandler"
scope="prototype">
</bean>
<bean id="searchHandler"
class="com.myown.SearchHandler"
scope="prototype">
</bean>
<bean id="searchBuilder"
class="com.myown.SearchBuilder"
scope="prototype">
</bean>
Where 'image' is a Singleton, I only need one instance in my app.
But its dependencies; 'imageHandler','searchHandler' and 'searchBuilder' are prototypes, they should be instanced everytime the user uses the class 'image'.In the class 'com.myown.ImageImpl' I have created setters for the dependencies, but these dependencies are only created once - so I am always stuck with my first search-criteria; let say if I search the first time with the keyword 'spring' and I get 10 results related to the spring-context, the second time I search and use the keyword 'dog' I get the same 10 results as the first time related to the spring-context and soforth.
Did put in the scope as prototype ( see thread by Xaeryan with the title 'Setter injection only happens once?' ) for my dependencies, but nothing happens.
If I skip IoC and code with :
' com.myown.ImageHandle imageHandler = new com.myown.ImageHandler () '.
within my com.myown.ImageImpl class then everything works just fine, I search for 'spring' and get a related searchresult and I search for 'dog' and get related searchresult.
So my problem is that the dependencies only happens once.
regards, Trott
ps.
I did fix this by using the interface BeanFactoryAware.
And private SearchHandler createSearchHandler() {
return (SearchHandler)this.beanFactory.getBean("searchHan dler") ;
}
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
this.beanFactory=beanFactory;
}
But is there another way solving this ?
ds.