I want to perform a simple task ! but dont know if it is possible or not!
I have a groovy class which implements Runnable and it has been running using an ThreadPool! what I want to do in my Runnable class is the following:
public void run() {
EventPhoto.withTransaction { status ->
EventPhoto photo = new EventPhoto(event:eventInstance)
photo.imageUrl = "${resource(dir:'images/uploads',file:image.name, absolute:true)}"
photo.thumbnailUrl = "${resource(dir:'images/uploads',file:thumb.name, absolute:true)}"
}
}
The thing is, as my thread is not running inside the webrequest I am getting the following error:
java.lang.IllegalStateException: No thread-bound request found: Are
you referring to request attributes outside of an actual web request,
or processing a request outside of the originally receiving thread? If
you are actually operating within a web request and still receive this
message, your code is probably running outside of
DispatcherServlet/DispatcherPortlet: In this case, use
RequestContextListener or RequestContextFilter to expose the current
request.
So Is there anyway to still use $resource() ??
thanks
Here is some information that will show you how to accomplish what you are trying to do. Also note that it advises that what you are doing is bad design.