I have a java web application using JSF, Spring and Hibernate frameworks. I want to write a batch program (with main() method) processing some data in the related database and I want to use some Spring Beans from the web application! Can anybody provide me with a proper guidance on how to access those beans from the main method without using a web request.
Add a comment
|
3 Answers
You wouldn't be able to "share" the actual runtime beans with a stand alone application, but you can re-create the same beans by creating an application context using the same xml files. If you actually want to re-use the runtime bean instances, you would have to "spawn" your application as a part of the web application, e.g. as a background thread, a scheduled Job, or just a management operation that can be triggered either by requesting a certain URL, or maybe via JMX.