title: IllegalArgumentException for dataSource in Spring application
body: <p>I am trying to deploy a simple spring app. It takes  a username(from a jsp), insets the value into a db and displays a greeting on a new jsp page saying <code>hello!, [username]</code>.</p>
  
  <p>My environment is:</p>
  
  <ul>
  <li>OS: windows xp professional</li>
  <li>Db: MS access (this is just for trying things out at first, intend to shift to mySQL)</li>
  <li>IDE: eclipse</li>
  <li>Server: Tomcat 6</li>
  </ul>
  
  <p>I get an error as below:</p>
  
  <pre><code>Feb 25, 2010 11:21:04 AM org.springframework.web.servlet.FrameworkServlet processRequest SEVERE: Could not complete request java.lang.IllegalArgumentException: dataSource is required
        at org.springframework.jdbc.support.JdbcAccessor.afterPropertiesSe(JdbcAccessor.java:130)
        at org.springframework.jdbc.core.JdbcTemplate.&lt;init&gt;(JdbcTemplate.java:122)
        at SpringClasses.Profile.setUsername(Profile.java:32) ………
  </code></pre>
  
  <p>The applicationContext file is as below:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" 
  "http://www.springframework.org/dtd/spring-beans.dtd"&gt;
  &lt;beans&gt;
  &lt;bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"&gt; 
      &lt;property name="dataSource"&gt;&lt;ref bean="dataSource"/&gt;&lt;/property&gt; 
  &lt;/bean&gt; 
  
  &lt;bean id="Profile" class="SpringClasses.Profile"&gt; 
      &lt;property name="dataSource"&gt;&lt;ref bean="dataSource"/&gt;&lt;/property&gt; 
  &lt;/bean&gt;
  
  &lt;bean id="dataSource"       class="org.springframework.jdbc.datasource.DriverManagerDataSource" singleton="true" destroy-method="close"&gt;
      &lt;property name="driverClassName" value="sun.jdbc.odbc.JdbcOdbcDriver"/&gt;
      &lt;property name="url" value="jdbc:odbc:usernamedb"/&gt;
      &lt;property name="username" value="admin"/&gt;
      &lt;property name="password" value=""/&gt;
  &lt;/bean&gt;
  &lt;/beans&gt;
  &lt;/code&gt;
  </code></pre>
  
  <p>I have set the DSN (usernamedb) under control panel ->admin tools->odbc sources->user DSN.The problem seems to be with the URL of the dataSource.</p>
  
  <p>The relevant java code from the controller class and bean class are as below</p>
  
  <p>From the ProfileFormController.java class:</p>
  
  <pre><code>protected ModelAndView onSubmit(Object command)
  {
    Profile profile = (Profile) command; 
    String greeting = "Hello," + profile.getUsername() + "!";
    profile.setUsername(profile.getUsername());
    return new ModelAndView("greetingDisplay", "greeting", greeting);
  }
  </code></pre>
  
  <p>From the Profile.java class:</p>
  
  <pre><code>private String username;
  private JdbcTemplate jt;
  private DataSource dataSource;
  
  public Profile() {
   }
  
  public Profile(String username) {
  this.username = username;
  }
  
  public String getUsername() {
  return username;
  }
  public String setUsername(String username) {
  int rowsInserted;
  setDataSource(dataSource);
  jt = new JdbcTemplate(dataSource);
  rowsInserted = jt.update("insert into username_db (username) values(?)",new Object[]      {username});
  
  //System.out.println("In Profile.getUsername, num. of rows inserted:"+rowsInserted);
  return username;
   }
  public void setDataSource(DataSource dataSource) {
   this.jt = new JdbcTemplate(dataSource);
    }
  </code></pre>
  
  <p>Configured the Profile bean in web.xml as below:</p>
  
  <pre><code>&lt;bean id="profileFormController" class="SpringClasses.ProfileFormController"&gt;
      &lt;property name="commandName"&gt;
         &lt;value&gt;profile&lt;/value
      &lt;/property&gt;
      &lt;property name="formView"&gt;
         &lt;value&gt;profile&lt;/value&gt;
      &lt;/property&gt;
      &lt;property name="successView"&gt;
         &lt;value&gt;greetingDisplay&lt;/value&gt;
      &lt;/property&gt;
  
   &lt;/bean&gt;
  </code></pre>
  
  <p>Within ProfileFormController, I'm setting the constructor as below: </p>
  
  <pre><code>public ProfileFormController() { 
    setCommandClass(Profile.class); 
    setCommandName("profile"); }
  </code></pre>
  
  <p>Added the contextLoaderServlet in web.xml too.</p>
  
  <p>What am I missing? Help is much appreciated.</p>
  
  <p>Thanks<br>
  Neetu.</p>