2012-12-12 3 views
1

RequestContextHolder.currentRequestAttributes().request은 성능에 영향을 줍니까? 나는 이것이 서비스 메소드 내에서 요청에 접근하는 것이 좋지 않다는 것을 안다. 그러나 나는 정말로 그것을 필요로한다. 따라서 RequestContextHolder.currentRequestAttributes().request 요청 당 20-30 번 전화하면 성능이 저하됩니까?RequestContextHolder.currentRequestAttributes(). 프로덕션 환경에서 request를 사용할 수 있습니까?

답변

1

문제는 성능과 관련이 없습니다. 전리적으로 서비스 메소드는 요청 (예 : 쿼츠 예약 된 작업) 외부에서 호출 될 수 있습니다. 이 경우 RequestContextHolder.currentRequestAttributes(). request가 예외를 throw합니다. 가장 좋은 방법은 매개 변수로 요청을 전달하여 필요한 서비스 메소드에 전달하는 것입니다.

class MyService{ 

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

} 

그리고 컨트롤러에서

class MyController{ 

def myService 

def index = { 

    myService.method(request) 

} 

} 
관련 문제