Я пытаюсь внедрить зависимость объекта сопоставления (класс TypeMapper), используя Spring следующим образом,
@Mapper(componentModel = "spring",
uses = {TypeMapper.class})
public interface AttachmentMapper {
AttachmentMapper MAPPER = Mappers.getMapper(AttachmentMapper.class);
@Mappings({
@Mapping(source = "type", target = "type") })
AttachmentDTO toDTO(Attachment attachment);
}
Код для TypeMapper выглядит следующим образом,
@Component
@Mapper
public abstract class TypeMapper {
public abstract Type mapType(DtoType DtoType);
@InheritConfiguration(name = "mapType")
public abstract DtoType mapDtoType(Type type);
}
Сгенерированный код AttachmentMapperImpl
следующий,
public class AttachmentMapperImpl implements AttachmentMapper {
@Autowired
private TypeMapper typeMapper;
public AttachmentDto toDTO(Attachment attachment) {
if ( attachment == null) {
return null;
}
attachmentDTO.setType(typeMapper.mapDtoType(attachment.getType()));
return attachmentDTO;
}
Проблема в сгенерированном коде, @Autowired typeMapper
пусто. Может кто-нибудь пролить свет на то, что я здесь делаю неправильно?