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

Factory Method 

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 getting a DriverManager instance by invoking a static factory method

File Name  :  

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

public class DriverManager {

  private static DriverManager clientService = new DriverManager();
  private DriverManager() {

  public static DriverManager getInstance() {
    return clientService;

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.DriverManager;

public class FactoryMethod {

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

    DriverManager driverMgr1 = (DriverManagerfactory.getBean("driverMgr1");
    DriverManager driverMgr2 = (DriverManagerfactory.getBean("driverMgr2");


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


bl  br