Dec 7th, 2010, 11:43 AM
performance issues due to use of reflection API in dependency injection
I am using Spring DI in domain objects using @Configurable and @Resource annotations. The rate of domain object creation is very high in my app. Since DI uses reflection, I have found that it results in high memory usage and high GC. I have confirmed this using java heap tool. This impacts the performance of the system and I am forced to change the design.
I came across the suggestion provided in
regarding the use of AbstractInterfaceDrivenDependencyInjectionAspect to bypass reflection.
Kindly note that I have a large variety of such domain objects which are created frequently and it is not possible to specify all the attributes to be injected by Spring, in a configureBean() as the list varies.
Has anyone faced similar performance issues. Is yes, kindly share any resolution ideas.
I would appreciate your advice in this regard.
Dec 9th, 2010, 02:45 AM
use @Component on your beans and do component-scanning, then use @Autowired on public setter methods. This way, Spring won't need to use reflection to dependency inject beans into other beans.