What is the best practice to get servlet context in service layer ?
+3
A:
There are a number of options, all of them wrong:
Put it in a
ThreadLocal
(i.e. per-request) and get it viaThreadLocalServletContextHolder.get()
Pass it as an argument to service methods
They are wrong, because the service layer should not know that it's servlets that are supplying it with data. Tomorrow it might be swing.
So the correct way is to gather all required parameters in the servlet (or controller), and pass them as arguments to the service layer. A worse option, but still not that bad is to get the Map
of attribute and pass it instead.
Bozho
2010-06-22 10:46:36
thanks, i will pass my required object as argumnet
Zeeshan
2010-06-22 11:46:37