title: Class path issue in Spring: File Not Found Exception
body: <p>I have a simple Java Spring IO project where a class  should read from a csv file and for each record read,  the parameters are stored into a list of  account objects.
  I'm using Force IDE Luna and the Class CsvAccountDao that reads the file is in the same package as the csv file which is defined in the first bean of the xml file.  The xml file is also located under the same package. Here is the bean file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;beans xmlns="https://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.1.xsd"&gt;
  
      &lt;bean id="accountDao"
      class="com.springinpractice.ch01.model.dao.csv.CsvAccountDao"&gt;
      &lt;property name="csvResource" value="accounts.csv"&gt;&lt;/property&gt;
      &lt;/bean&gt;
      &lt;bean id="accountService"
              class="com.springinpractice.ch01.service.AccountService"&gt;
              &lt;property name="accountDao" ref="accountDao"&lt;/property&gt;     
          &lt;/bean&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>and here is the class file CscAccountDao:</p>
  
  <pre><code>package com.springinpractice.ch01.model.dao.csv;
  import java.io.BufferedReader;
  import java.io.FileReader;
  import java.math.BigDecimal;
  import java.text.DateFormat;
  import java.text.SimpleDateFormat;
  import java.util.ArrayList;
  import java.util.Date;
  import java.util.List;
  import org.springframework.core.io.Resource;
  import com.springinpractice.ch01.model.Account;
  import com.springinpractice.ch01.model.dao.AccountDao;
  
  public class CsvAccountDao implements AccountDao {
      private Resource csvResource;
  
      public CsvAccountDao() {
          // TODO Auto-generated constructor stub
      }
      public void setCsvResource(Resource csvFile){
          this.csvResource = csvFile;
      }
      @Override
      public List&lt;Account&gt; findAll() throws Exception {
          List&lt;Account&gt; results = new ArrayList&lt;Account&gt;();
  
          DateFormat fmt = new SimpleDateFormat("MMddyyyy");
          BufferedReader br = new BufferedReader(
                  new FileReader(csvResource.getFile()));
          String line;
          while((line = br.readLine()) != null){
              String[] fields = line.split(",");
  
              String accountNo = fields[0];
              BigDecimal balance = new BigDecimal(fields[1]);
              Date lastPaidOn = fmt.parse(fields[2]);
              Account account =
                          new Account(accountNo, balance, lastPaidOn);
              results.add(account);
          }
          br.close();
          return results;
      }
  }
  </code></pre>
  
  <p>Note where method setCsvResource assigns the csv file to the resource object is where the exception problem begins. I get an exception error in the stack trace  that says:</p>
  
  <pre><code>Jun 20, 2015 7:59:42 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
  INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@177e4b0: defining beans [accountDao,accountService]; root of factory hierarchy
  Exception in thread "main" java.io.FileNotFoundException: class path resource [accounts.csv] cannot be resolved to URL because it does not exist
  </code></pre>
  
  <p>Q) Is there a problem where I would have to updated the XML file where the first bean uses accounts.csv by adding a full path? Since the both the class,xml,  and the csv files are within the same package I thought I didn't need to be more specific.</p>