I will expose my problem.
I'm writing Swing applications and I like using Spring in my client (not very common in a Swing application) because it is useful when you call some Remote Services (RMI, WS) by using the different Spring Proxy Clients or if you want to seperate your Business logic and GUI logic and so easy to test your gui.
The problem using Spring in Swing application is when you're making a Swing application, you need to inject in your Controller/View (JPanel for instance) some beans Spring. But your JPanel is not instanciated by Spring (and you can't it).
To resolve this problem, I found 2 solutions
- create a kind of ServiceLocator (where the applicationContext is instanciated). When you want to inject a bean Spring, you must ServiceLocator.getInstance().getYourSpringBean(). It is very old-fashioned and has all problems related to static singleton (not easy too test, problem in Netbeans RCP like Tomcat for static stuffs ...).
- use @Configurable on your panel (not instanciated by Spring) to inject with @Autowired in some spring bean. It very clean and elegant on my point of view.
I made a small application with @Configurable and it works but it reveals some performance and memory usage problems.
When you use a GUI with a ServiceLocator, the startup of this application is something like 2 s (1s for Swing and 2s for spring context in lazy mode) and the memory usage is 10 mo.
When you use the same GUI with @Configurable (with the spring agent) the startup of the application is something like 10 s and the memory usage is 50-60 mo.
I attached a very small application example to show the problem. With this sample,
when you use a GUI with a ServiceLocator, the startup of this application is something like 900 ms (250 ms for Swing and 650 ms for spring context in lazy mode) and the memory usage is 1.2 mo.
When you use the same GUI with @Configurable (with the spring agent) the startup of the application is something like 3.6 s (1350 ms for Swing and 2280 ms for spring context in lazy mode) and the memory usage is 8 mo.
So the performance and memory usage is degraded by 5.
I tested with Spring 2.5.6 and with 3.0RC1 and the behaviour is the same.
Can you explain this behaviour? Is it normal? Maybe I have misconfigured my applicationContext. Can I specify the package where @Configurable classes are located to improve performance?
Honnestly, with these problems, @Configurable is just unuseable for production GUI application but only for unit tests.