As i consume a lot of data in httpservletrequest header and set a lot of values in request attribute in service class, I'm not sure if this would cause thread safety issues, I looked over the web if autowiring httpservlet request would cause threadsafety issues and i got mixed opinion
Following are the places where i autowire httpservletrequest
@RestController
Public class UserController {
@Autowire
HttpServletRequest httpServletRequest;
@Autowire
IAMService iamservice;
@PostMapping("/addUser")
public String addUser(@RequestBody UserDto userdto){
return iamservice.addUser(userdto);
}
}
@Service
Public Class IAMService {
@Autowire
HttpServletRequest httpServletRequest;
@Autowire
UserDao userDao;
public String addUser(UserDto userdto){
Long primaryKey = userDao.save(userdto,httpServletRequest.getHeader("loggedInUserId"));
httpServletRequest.setAttribute("userPrimaryKey",primaryKey);
return "User is added successfully";
}
}