I can’t inject dependency in mapper, what’s wrong?
@Mapper(componentModel = "spring", uses = { UserMapperHelper.class })
public interface ReminderCreateMapper {
@Mapping(target = "id", ignore = true)
@Mapping(source = "userId", target = "user")
Reminder reminderCreateDtoToReminder(ReminderCreateDto dto);
}
@Mapper(componentModel = "spring", uses = {UserService.class})
public interface UserMapperHelper {
User toEntity(Long userId);
}
@Service
@Transactional(readOnly = true)
@RequiredArgsConstructor
public class UserServiceImpl implements UserService {
private final UserRepository userRepository;
public User findById(Long id) {
return userRepository.findById(id).orElseThrow(() -> new RuntimeException());
}
}
But
java.lang.NullPointerException: Cannot invoke "ru.lebedev.reminder.mapper.UserMapperHelper.toEntity(java.lang.Long)" because "this.userMapperHelper" is null
I tried to use mapstruct map an id to an object
but it does’t work.
3