Static Factory : Xml Bean Factory « Spring « Java Tutorial






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)








28.6.Xml Bean Factory
28.6.1.Xml Bean Factory Demo
28.6.2.Static Factory
28.6.3.Compare Beans From Factory Bean
28.6.4.Create XmlBeanFactory from ClassPathResource
28.6.5.BeanFactory Aware
28.6.6.Non Static Factory
28.6.7.Hierarchical BeanFactory Demo
28.6.8.Add BeanFactory PostProcessor To XmlBeanFactory
28.6.9.Add addBeanPostProcessor To XmlBeanFactory