I have a Spring web project and I need load some classes after application context has been initialized because those classes will eventually used in future. Thus, I try to preload them before use to improve performance.
How to do it ?
Please help.
Thanks.
To load a class into JVM it is enough simply to call
Class.forName('com.foo.bar.MyClassToPreLoad')method.You can do it e.g. in your own implementation of
javax.servlet.ServletContextListenerand then register it in web.xmlOr you can do it in any of your Spring beans implementing
org.springframework.beans.factory.InitializingBeaninterface. Or if you don’t want to implement interface you can do it in any bean method without arguments and register it as a init-method for this bean:See http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/beans.html#beans-factory-lifecycle-initializingbean for details.
Or http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/beans.html#beans-postconstruct-and-predestroy-annotations if you prefer annotation based configuration.
Hope it helps.