views:

86

answers:

1

Is there a way to get a resource in a spring web application using a simple Resource? I am trying not to pass any context, and need to obtain a file from the WEB-INF/freemarker/email/ directory.

+3  A: 

No. Since the WEB-INF/freemaker/email is not on the classpath, you need to pass ServletContext. As you mention Resource, you can use:

Resource resource = new ServletContextResource(servletContext, resourcePath);

Just don't pass the ServletContext to the service layer. Pass the Resource instead.

If you want to obtain the template from the classpath, place it there. That is, for example, in:

WEB-INF/classes/freemaker/email

Then you can use ClassPathResource

Bozho
specifically in this case, i am trying to get a freemarker template - even using ClasspathResource, and passing the full filename to the Freemarker Template i get exceptions. I am just looking for the easiest way to obtain a ftl from the classpath. You have any idea, or should i create a new question?
wuntee
@wuntee see my update
Bozho