Environment :
Spring MVC 3
Angular JS
Tomcat 6
Issue :
We are migrating a legacy application from struts2 to spring MVC REST with angular JS as UI.
This is a typical SPA.
The typical application flow is : Angular JS + Spring REST controller + Servicelayer
The business logic in struts2 actions is moved to service classes.
My question is - What is the correct way to make HttpServetRequest object available to Service classes in Spring ?
Two options available are :
1)Pass HttpServletRequest to Spring MVC controller method. Pass the same HttpServetRequest to Spring service layer.
But this will result in HttpServletRequest being part of Service interface like -
public ProductDto getProductDetails(HttpServletRequest req,int productId)
Is this a correct way ? Can HttpServletRequest be part of Service interface ?
2)Use Spring provided API :
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
Please guide on this ?