2012-01-05 19 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

相關問題