I'm quite new to Spring (Boot, latest version) and I have a problem with a mapper in a REST service. I have some UserMapper which maps, for instance, model user object (UserOP) to logic user object (User).
Users have an Address and I have to map it along with the user. The problem is, I don't succeed in injecting correctly my AddressMapper in the UserMapper.
I tryied the following but mapperAddress is null (Spring compiles, so I guess it just does not do the part "mapperAddress = new AddressMapper()
"). Can someone explain me why and how to do it properly ? I searched on the Internet but did not understand.
@Component public class UserMapper {
public UserMapper() {
super();
}
@Autowired
private AddressMapper mapperAddress;
public User modelToIo(UserOP userOp){
User user = null;
if (userOp != null){
User = new User();
user.setAddress(mapperAddress.modelToIo(userOp.getAddress()));
...
}
}
...
}
and
@Component
public class AddressMapper {
public AddressMapper() {
super();
}
...
}
Thanks.