Simple Spring, using ClasspathApplicationContext for stand-alone applications, how to reuse them?

If I have a separate main application. Say 20 classes. All of them can at any time interact with beans, defined by the spring configuration (ApplicationContext). I would load the classpath application context at the main entry point of the application. But how do you reuse beans already created?

For example, this seems like a poor approach to setting ClasspathApplicationContext as a singleton, but that would be an idea.

I thought I saw a GlobalContextLocator or something like that, but did not see an example of how to use it.

+4
source share
1 answer

. :

http://static.springframework.org/spring/docs/2.5.x/reference/beans.html#context-introduction

, , - SingletonBeanFactoryLocator ContextSingletonBeanFactoryLocator.

SingletonBeanFactoryLocator, beans:

BeanFactoryLocator bfl = SingletonBeanFactoryLocator.getInstance();
BeanFactoryReference bf = bfl.useBeanFactory("com.mycompany.myapp");
MyClass zed = bf.getFactory().getBean("mybean");

Javadocs :

http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/beans/factory/access/SingletonBeanFactoryLocator.html

, , , , .

+4

All Articles