【发布时间】:2022-07-17 20:36:27
【问题描述】:
我正在尝试使用 mapstruct 注入我的映射器,但 spring 无法识别 bean。
这是我的映射器
package com.api.gestioncartera.Services.Mappers;
import org.mapstruct.Mapper;
import org.springframework.stereotype.Component;
import com.api.gestioncartera.Entities.CollectionCompany;
import com.api.gestioncartera.Services.DTO.CollectionCompanyDto;
@Mapper(componentModel = "spring")
public interface CollectionCompanyMapper {
CollectionCompanyDto collectionCompanyToCollectionCompanyDto(CollectionCompany collectionCompany);
}
我正在尝试注入我的服务
@Service
@Transactional
public class CollectionCompanyServiceImp implements CollectionCompanyService{
@Autowired
private CollectionCompanyMapper companyMapper;
}
我的 gradle 配置
plugins {
id 'org.springframework.boot' version '2.5.6'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
...
dependencies {
...
implementation 'org.mapstruct:mapstruct:1.4.2.Final'
annotationProcessor 'org.mapstruct:mapstruct-processor:1.4.2.Final'
}
compileJava {
options.compilerArgs += [
'-Amapstruct.suppressGeneratorTimestamp=true',
'-Amapstruct.suppressGeneratorVersionInfoComment=true',
'-Amapstruct.verbose=true',
'-Amapstruct.defaultComponentModel=spring'
]
}
我还在 IDE 中启用了启用注释处理 Properties in the IDE
错误是:
考虑在您的配置中定义一个“com.api.gestioncartera.Services.Mappers.CollectionCompanyMapper”类型的 bean。
我注意到我没有任何插件引用 mapstruct,这可能是问题吗?图片:
我正在使用 Spring Tool Suite 4 (Eclipse) + Gradle 6.8 + SrpingBoot 2.5.6 请帮忙!!
【问题讨论】:
-
您是否检查了 CollectionCompanyMapper 的实现是否正确生成,在项目中编译并查看
-
如何查看?
-
检查 target/generated_sources 文件夹
-
我运行项目并注释了 inejction,我检查了文件夹 .apt_generated 并且是空的,MapStruct 没有创建实现
-
我没有“target/generated_sources”文件夹
标签: spring spring-boot mapstruct mapper