"julien(a)jboss.com" wrote :
| Please try to get an answer understandable by someone that has little knowledge about
MC.
This isn't really an MC question, it's a programming patterns question :-)
The answer is to use a factory/singleton pattern.
e.g. These two would use the object constructed by MyFactory
(which can also be an instance class rather than the shown static method).
| <bean name="Bean1">
| <constructor factoryClass="MyFactory"
factoryMethod="getInstance"/>
| </bean>
|
| <bean name="Bean2">
| <constructor factoryClass="MyFactory"
factoryMethod="getInstance"/>
| </bean>
|
| ALTERNATIVE:
|
| If you don't like the boiler plate of coding a singleton factory,
| I wrote an aspect that does it for you:
|
http://viewvc.jboss.org/cgi-bin/viewvc.cgi/jbossas/projects/aop/trunk/asp...
| which I guess could also be configured with an annotation (although it doesn't
exist currently).
|
|
| | <bind pointcut="execution((a)com.acme.Singleton->new())">
| | <advice name="constructorAdvice"
aspect="Singleton"/>
| | </bind>
| |
| | @com.acme.Singleton
| | public class MyBean {}
| |
|
| I'm sure you can adapt it to your needs if it doesn't do exactly what you
want. ;-)
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4130750#...
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&a...