Results 1 to 2 of 2

Thread: ClassPathResource throws IOException

  1. #1
    Join Date
    Jun 2009
    Location
    Vicenza, Italy
    Posts
    84

    Default ClassPathResource throws IOException

    Hi everybody,
    I am having a problem on using ClassPathResource.
    I defined my resource as a bean
    Code:
    <bean id="welcome_mail_template" class="org.....ClassPathResource">
        <constructor-arg value="classpath:mails/welcome.txt" />
    </bean>
    Then I wired it up with my mail client class
    Code:
    <bean id="mail_client" class="it......MailClient">
        <property name="welcomeMail" ref="welcome_mail_template" />
    </bean>
    but when i try to call the getFile() method on my resource from within the MailClient, it throws an IOException. The code that throws the exception is:
    Code:
    File f = this.getWelcomeMail().getFile();
    where getWelcomeMail() is the getter to obtain the resource (that is declared as interface Resource)

    The exception is a FileNoutFoundException, the message is "class path resource [classpath:mails/welcome.html] cannot be resolved to URL because it does not exist", but I have yet check more than once and paths and names seem to be correct.

    Can anybody help me? What am I doing wrong?

    --Stefano

  2. #2
    Join Date
    Jun 2009
    Location
    Vicenza, Italy
    Posts
    84

    Default

    I found the problem... really silly, indeed.
    Simply the ClassPathResource object bean was incorrect: in the path, you don't have to add "classpath:" and it works.

    --Stefano

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •