2012-01-05 21 views
2

我正在使用Grails 2.0.0,并尝试从Bootstrap.groovy预先填充一些测试数据。这些数据需要Grails taglib的createLinkToGrails 2.0 - 如何在Bootstrap或后台线程中使用createLinkTo

顺便说一句,当我试图调用g.createLinkTo(...)我越来越:

Message: 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. 

而且也,这个应用程序将使用在后台线程createLinkTo(事件处理,发送邮件等)。所以我不仅需要Bootstrap。

据我所知,我需要做一个模拟请求,并将其绑定到当前线程,但我怎么能做到这一点?

或者也许有另一种方式来使应用程序链接?

回答

4

Grails中2,你可以使用LinkGenerator

已在链接生成API部分看看here

+0

如果您不在请求线程中,则不适用。 LinkGenerator和DefaultRequestStateLookupStrategy假定您从请求线程使用它。您进入后台线程时唯一的选择是在LinkGenerator上设置serverBasedUrl和contextPath以使其工作。否则,它会为绝对URL返回http:// localhost /。没有端口,没有包含contextPath。 – chubbsondubs 2013-12-10 20:54:31

相关问题