tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Spring > Core > Factory Bean

Factory Bean 

Spring Inversion of Control (IoC) also known as Dependency Injection (DI) is a process by which objects define their dependencies with collaborating objects. This example shows invoking an instance factory method on a bean instance.

File Name  :  

File Name  :  
package com.bethecoder.tutorials.spring3.basic;

public class Foo {
  public Bar createBar() {
    return new Bar();
  public static class Bar {

File Name  :  
Author  :  Sudhakar KV
Email  :  [email protected]
package com.bethecoder.tutorials.spring3.tests.factory;

import org.springframework.beans.factory.xml.XmlBeanFactory;

import com.bethecoder.tutorials.spring3.basic.Foo;

public class FactoryBean {

   @param args
  public static void main(String[] args) {
    XmlBeanFactory factory = new XmlBeanFactory(
                new ClassPathResource("factory_bean.xml"));

    Foo foo = (Foofactory.getBean("foo");
    Foo.Bar bar  = (Foo.Barfactory.getBean("bar");


It gives the following output,
[email protected]
[email protected]



Books Recommendation

bl  br