Announcement Announcement Module
No announcement yet.
ClassPathResource throws IOException Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • ClassPathResource throws IOException

    Hi everybody,
    I am having a problem on using ClassPathResource.
    I defined my resource as a bean
    <bean id="welcome_mail_template" class="org.....ClassPathResource">
        <constructor-arg value="classpath:mails/welcome.txt" />
    Then I wired it up with my mail client class
    <bean id="mail_client" class="it......MailClient">
        <property name="welcomeMail" ref="welcome_mail_template" />
    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:
    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?


  • #2
    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.