In the simple spring rest controller class below, should the @RequestBody model object/component AUser
be singleton or prototype. I want to check this because, each request is served by a separate thread with different values for AUser
, so if the AUser
class is of default Singleton type, won't the requests from various threads hitting simultaneously override each others data.
@RestController
@Component
public class ExampleController {
@PostMapping("/hello")
public String sayHello(@RequestBody AUser user) {
return "hello " + user.userName + " from " + user.userCity;
}
}
@Component
class AUser {
public String userName;
public String userCity;
}