Non Static Factory : XML Bean « Spring « Java






Non Static Factory

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="nonStaticFactory" class="NonStaticFactory"/>
  <bean id="testBeanObtainedViaNonStaticFactory"
        factory-bean="nonStaticFactory" 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("testBeanObtainedViaNonStaticFactory");
  
  
  }
}

class NonStaticFactory {
  public TestBean getTestBeanInstance() {
    return new TestBean();
  }
}


class TestBean {
   
  
}



       

           
       








Spring-NonStaticFactory.zip( 2,893 k)

Related examples in the same category

1.XML Bean Injection
2.Reference another bean and set property
3.Static Factory
4.Serach By Base Package
5.throw RequiredPropertyNotSetException
6.Properties File Based Spring Bean
7.Local Reference
8.Link With DataSource
9.Inheritance Demo
10.HierarchicalBeanFactory Demo
11.Filtered By Annotation
12.destroy method
13.dependency check Demo
14.Custom InitializationMethod
15.component scan
16.Component Scan and scope
17.Component Filter Assignable
18.implements BeanNameAware
19.Bean Lifecycle Initializing
20.Bean Lifecycle DisposableBean
21.Autowiring
22.Alias Bean Demo