01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tctest.spring.bean;
05:
06: import org.springframework.beans.factory.InitializingBean;
07: import org.springframework.beans.factory.config.AbstractFactoryBean;
08: import org.springframework.context.ApplicationContext;
09: import org.springframework.context.support.ClassPathXmlApplicationContext;
10:
11: public class SingletonFromSeparateContextFactoryBean extends
12: AbstractFactoryBean implements InitializingBean {
13: private String beanDefLocation = null;
14: private ApplicationContext ctx = null;
15:
16: public Class getObjectType() {
17: return Singleton.class;
18: }
19:
20: public void afterPropertiesSet() throws Exception {
21: ctx = new ClassPathXmlApplicationContext(
22: new String[] { beanDefLocation });
23: super .afterPropertiesSet();
24: }
25:
26: protected Object createInstance() throws Exception {
27: return ctx.getBean("singleton");
28: // return new Singleton();
29: }
30:
31: public String getBeanDefLocation() {
32: return beanDefLocation;
33: }
34:
35: public void setBeanDefLocation(String beanDefLocation) {
36: this.beanDefLocation = beanDefLocation;
37: }
38: }
|