I am working with Spring MVC controller. I have one of my controller as DataController.
I am thinking to add HttpServletRequest as injectable at the top of DataController class using @Inject.
@Controller
public class DataController {
@Inject
HttpServletRequest request;
// .. some code here
@RequestMapping(value = "process", method = RequestMethod.GET)
public @ResponseBody
DataResponse processTask(@RequestParam("workflow") final String workflow) {
String ipAddress = request.getRemoteAddr();
System.out.println(ipAddress);
}
So my question is - Is this the right way to use @Inject? I have never used @Inject before so trying to learn whether the way I am doing it is right or not? Since everytime, who is making call to processTask method, I need to grab its ipAddress whoever is calling that processTask method.