Simple Spring, use of ClasspathApplicationContext for standalone apps, how to reuse?

Simple Spring, use of ClasspathApplicationContext for standalone apps, how to reuse?

If I have a standalone main application. Say 20 classes. They all may need to interface with the beans defined by the spring configuration (ApplicationContext) at any time. I would bootstrap the classpath application context at the main application entry point. But how do you reuse the already instantiated beans?

For example, it seems like a bad approach to setup the ClasspathApplicationContext as a singleton, but that would be the idea.

I thought I had seen a GlobalContextLocator or something along those lines but didn't seen an example on how to use it.

JTA: how to be test JMS and JDBC failures?


maintain state with spring between requests
There are a number of ways to do it.

Interoperability by using Spring and Hessian ? Is it possible?
Your best reference is here:.
Spring Hibernates session issue with http request
WAS 6.1, JPA with JTA, Hibernate, Spring : data retrieval problem
and the specific classes you need to look at are SingletonBeanFactoryLocator and ContextSingletonBeanFactoryLocator.

Using JSF, JPA and DAO. Without Spring?
How to register multiple servlets in web.xml in one Spring application
If you use the SingletonBeanFactoryLocator you can use the following to look up beans:.
Setting createdBy and updatedBy in JPA entities automatically
BeanFactoryLocator bfl = SingletonBeanFactoryLocator.getInstance(); BeanFactoryReference bf = bfl.useBeanFactory("com.mycompany.myapp"); MyClass zed = bf.getFactory().getBean("mybean"); 
There is a very good explanation of this in detail in the Javadocs:. Also, just to be clear, make sure that the config file is in your classpath for your application, otherwise the lookup will fail..

85 out of 100 based on 65 user ratings 865 reviews