使用Spring boot 3 + gradle 学习时遇到一个奇怪的错误
spring boot gradle 同时使用lombok 和 mapstruct 报错 Parameter 1 of constructor in xxxx.xxxx.xxx.service.impl.xxxxServiceImpl required a bean of type ’ xxxx.xxxx.xxx.service.mapstruct.xxxxxMapper’ that could not be found.
抛出的异常: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type ‘xxx.xxx.xxx.service.mapstruct.xxxMapper’ available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}

当时很奇怪,通过搜索引擎发现,大多数的结果都是在启动类添加@ComponentScan、@MapperScan 等等
后来怀疑是怀疑是因为引入依赖的方式不正球,后面刚好看到一篇文章:当 Lombok 遇见了 MapStruct の「坑」里面提到 “Lombok 和 MapStruct 都是利用「Annotation Processor」在程序编译时生成代码的” 顿时意识到我引入依赖的方式错了

我的引入方式

implementation 'org.mapstruct:mapstruct:1.5.5.Final'
implementation 'org.mapstruct:mapstruct-processor:1.5.5.Final'

正确引入方式

implementation 'org.mapstruct:mapstruct:1.5.5.Final'
annotationProcessor 'org.mapstruct:mapstruct-processor:1.5.5.Final'

兜了一个大圈子/无辜脸/

标签: Java

添加新评论