Announcement Announcement Module
Collapse
No announcement yet.
ClassPathResource throws IOException Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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
    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
    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

    Comment

    Working...
    X