File: context.xml
"http://www.springframework.org/dtd/spring-beans.dtd">
class="StaticFactory" factory-method="getTestBeanInstance"/>
File: Main.java
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
class Main {
public static void main(String args[]) throws Exception {
ApplicationContext ctx = new ClassPathXmlApplicationContext("context.xml");
TestBean testBeanObtainedViaStaticFactory = (TestBean) ctx
.getBean("testBeanObtainedViaStaticFactory");
}
}
class StaticFactory {
public static TestBean getTestBeanInstance() {
return new TestBean();
}
}
class TestBean {
}
Spring-StaticFactory.zip( 2,893 k)