首页 > 解决方案 > 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);
}

我的安装ServiceImpl:

@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;
}

标签: javajakarta-eecdiinjectmapstruct

解决方案


推荐阅读