I made a common Manager and a common Bean to access different tables of my DB (using hibernate).
In a controller, i'm using @Autowired & @Qualifier to automaticly get my bean.
It works pretty well, but now, i'm facing a problem.
I need multiple instance of the common Manager in my controller.
Here is my code :
Here is a part of my springmvc-servlet.xml
The thing is : tlocationManager, tcommManager and initiativManager are the SAME object !
I need it to be different instances..
I searched on the web and found out that you add to a bean definition an attribute or a property singleton="false".
Unfortunately, i tryed it and i've got an error saying this attribute/property is not valid.
How can i solve it ?
Your help would be really appreciated !
Mark Spritzler wrote:Well you can define three different beans with different ids, but the same class, then qualify each instance variable to each of the three beans.
You can also try <bean scope="prototype"
adding scope="prototype" to your bean definition and that might work.
Why do you need three? Does the bean hold any state, if not, one bean should be plenty to support as many clients using it at the same time.
The CommonManager instanciate a CommonDao (using Hibernate). The table reached by the DAO depends of the class used to define the CommonManager.
Eg: private CommonManager<Initiative> initiativManager; => the methods getList() or getObjectById(long ident ) of my DAO will reach my Initiative table.
That is why i need three instances... However, since the CommonManager instanciate the CommonDao using @Autowired, the same instance of the bean CommonDao is also used.. So, generating three beans of the same class CommonManager won't resolve the problem since it'll still uses the same CommonDao.
I resolved my problem by using this :
In my Controller :
And the class CommonTypePropertyEditor.java :
However, i don't understand how come it's possible to use the same instance of an object but with different declarations..
I mean.. I have ONE instance of the CommonManager bean, but once as <TypeLieu>, once as <TypeCommunication> and once with <Initiative>...
Can you explain this ?
Still, i'm going to try your solution.
Thanks a lot for your reply and sorry if my english isn't that good :P