File: context.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="testBeanObtainedViaStaticFactory"
class="StaticFactory" factory-method="getTestBeanInstance"/>
</beans>
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 {
}
Download: Spring-StaticFactory.zip( 2,893 k)