MapStruct-第二个映射器的焊缝注入不起作用

时间:2019-04-05 15:25:28

标签: java java-ee cdi inject mapstruct

我对使用mapstruct库的映射器的焊缝cdi注射有问题。 当我只有一个映射器时,一切正常。 添加第二个映射器后,此映射器将引发异常: 由以下原因引起:org.jboss.weld.exceptions.DeploymentException:WELD-001408:类型为带有限定符@Default

的InspectionTypeMapper的不满足依赖性

第一个映射器(此映射器有效)

@Mapper(componentModel = "cdi", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface InstallationMapper {
    Installation installationDtoToInstallation(InstallationDto installationDto);
    InstallationDto installationToInstallationDto(Installation installation);
    List<InstallationDto> installationsToInstallationsDtos(List<Installation> installations);

}

第二个映射器(这不起作用并抛出异常):

@Mapper(componentModel = "cdi", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface InspectionTypeMapper {
    InspectionType inspectionTypeDtoToInspectionType(InspectionTypeDto inspectionTypeDto);
    InspectionTypeDto inspectionTypeToInspectionTypeDto(InspectionType inspectionType);
    List<InspectionTypeDto> inspectionTypesToInspectionTypeDtos(List<InspectionType> inspectionTypes);
}

我的installationServiceImpl:

@RequestScoped
public class InstallationServiceImpl implements InstallationService {
@Inject
private InstallationRepository installationRepository;
@Inject
private InstallationMapper installationMapper;

@Override
public List<InstallationDto> getAllInstallations() {
    List<Installation> installations = installationRepository.getAll();
    List<InstallationDto> installationDtos = installationMapper.installationsToInstallationsDtos(installations);
    return installationDtos;
    }
}

我的InspectionTypeServiceImpl:

@RequestScoped
public class InspectionTypeServiceImpl implements InspectionTypeService{
@Inject
InspectionTypeRepository inspectionTypeRepository;

@Inject
InspectionTypeMapper inspectionTypeMapper;
@Override
public List<InspectionTypeDto> getAllInspectionTypes() {
    List<InspectionType> inspectionTypes = inspectionTypeRepository.getAll();
    System.out.println(inspectionTypes);
    List<InspectionTypeDto> inspectionTypeDtos = inspectionTypeMapper
            .inspectionTypesToInspectionTypeDtos(inspectionTypes);
    return inspectionTypeDtos;
}

0 个答案:

没有答案