In case you want some sample code, I've just done something similar myself anyway...
Your HandlerIntercepter would look something like:
Code:
public class WebInterceptor extends HandlerInterceptorAdapter {
public boolean preHandle(
HttpServletRequest request,
HttpServletResponse response,
Object handler)
throws Exception {
CurrentThread.setCustomer((Customer)request.getSession().getAttribute("sessionCustomer"));
return true;
}
}
And where ever you access it like (which can be done using AOP):
Code:
CurrentThread.getCustomer();
And the ThreadLocal:
Code:
public class CurrentThread {
private static ThreadLocal customer = new ThreadLocal();
public static Customer getCustomer() {
if (customer.get()==null) {
return null;
}
return (Customer) customer.get();
}
public static void setCustomer(Customer customerIn) {
customer.set(customerIn);
}
}