0

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.

3 Answers 3

1
  ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("xml1", "xml2");
  context.getBean("Somebean");
Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

0

You should refer these two links.

1.) ClassPathXmlApplicationContext API

2.) Example

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.