title: convert Singelton to Java Spring
body: <p>I have created a database object according to the singleton pattern. The database object contains 2 methods: connect() and update().</p>
  
  <p>I want to convert this singelton to Spring bean.</p>
  
  <p>So I've created an XML file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"&gt;
  
      &lt;bean id="MySingeltonDB"
          class="SingeltonDBVersion2.SingeltonDB" factory-method="getInstance"&gt;&lt;/bean&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>adn the SingeltonDB class: </p>
  
  <pre><code>package SingeltonDBVersion2;
  public class SingeltonDB {
      private static DBconnImpl db = null;
      private static SingeltonDB singalDb = null;
  
      private SingeltonDB(String username, String password) {
          db = new DBconnImpl();
      }
  
      public static boolean isOpen() {
          return (db != null);
      }
  
      public synchronized static SingeltonDB getInstance(String username,
              String password) throws Exception {
  
          if (db != null) {
              return singalDb;
          }
          System.out.println("The database is now open");
          singalDb = new SingeltonDB(username, password);
          db.connect(username, password);
          System.out.println("The database was connected");
          return singalDb;
      }
  
      public void create(String tableName) throws Exception {
          db.create(tableName);
      }
  
      public User query(String tableName, int rowID) throws Exception {
          if (db == null) {
              System.out.println("Error: the database is not open");
              return null;
          }
          return (db.query(tableName, rowID));
      }
  
      public void update(String tableName, User user) throws Exception {
          if (db == null) {
              System.out.println("Error: the database is not open");
              return;
          }
          db.update(tableName, user);
      }
  
  }
  </code></pre>
  
  <p>and this is the Main class:</p>
  
  <pre><code>package SingeltonDBVersion2;
  import org.springframework.context.ApplicationContext;
  import org.springframework.context.support.ClassPathXmlApplicationContext;
  
  public class Main {
      public static void main(String[] args) throws Exception {
          ApplicationContext context =new ClassPathXmlApplicationContext("spring.xml");
  
      }
  }
  </code></pre>
  
  <p>but I am getting this error:  <strong><em>Error creating bean with name 'MySingeltonDB' defined in class path resource [spring.xml]: Unsatisfied dependency expressed through constructor argument with index 1 of type [java.lang.String]: Ambiguous factory method argument types - did you specify the correct bean references as factory method arguments?</em></strong></p>
  
  <p>Can somebody please help me? I am new in spring so I might not configured everything proprely...
  Thanks!</p>