How can I inject @RequestBody object(value object) to Spring Service layer?
I want to Inject(Autowired)objects what come from request body values.
HelloController
@Autowired
UserService userService;
(….)
@GetMapping("/hello")
public String hello(
@RequestBody UserRequestBodyDto userDto,
HttpServletResponse response){
return null;
}
UserRequestBodyDto
@Data
public class UserRequestBodyDto{
private String name;
private String address;
}
UserServiceImpl
@Service
public class UserServiceImpl implements UserService{
@AutoWired
public UserServiceImpl(UserRequestBodyDto userDto){
(….)
}
}
In that case, how can I inject UserRequestBodyDto objects into service layer?
Add 'setUserDto' method to UserService is the best way? or If convert dto to entity is the best way to inject objets, how can I manage many of same classes between dto class and entity class?
+a) In my opinion, make a RequestScopedBean is bad way.