2012-12-12 35 views

回答

1

該問題與perfomance無關。本人可以在請求之外調用服務方法(例如,在石英預定作業中)。在這種情況下,RequestContextHolder.currentRequestAttributes()。request可能會引發異常。我認爲最好的方式是將請求作爲參數傳遞給需要它的服務方法。

class MyService{ 

def method(def request){ 
    //do what you want with the request 
} 

} 

以及來自控制器

class MyController{ 

def myService 

def index = { 

    myService.method(request) 

} 

} 
相關問題