0
我想這個工作對讀消息包(Grails的2.0,石英0.4.2):使用應用程序上下文
class Job1Job {
def timeout = 5000l // execute job once in 5 seconds
def grailsApplication
def execute() {
def ctx = grailsApplication.mainContext
def bean = ctx.getBean('org.codehaus.groovy.grails.plugins.web.taglib.ApplicationTagLib')
println bean.message(code:'default.home.label')
}
}
而得到錯誤:
Error 2011-12-28 14:30:14,021 [quartzScheduler_Worker-5] ERROR listeners.ExceptionPrinterJobListener - Exception occured in job: GRAILS_JOBS.testappcontext.Job1Job
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.
代碼在控制器和服務中完美工作。我做錯了什麼? 我懷疑這個代碼的Grails 1.3.7
謝謝。是否可以傳遞消息參數?我的代碼不起作用:messageSource.getMessage('default.list.label',[「!」],Locale.default) – 2011-12-28 15:19:29
第二個arg是一個Object數組,因此應該是'messageSource.getMessage('default。 list.label',['!']爲Object [],Locale.default)' – 2011-12-28 15:32:19