当前位置:网站首页>记录一些遇见的bug——Lombok和Mapstruct的冲突导致,A component required a bean of type ‘com.XXX.controller.converter.
记录一些遇见的bug——Lombok和Mapstruct的冲突导致,A component required a bean of type ‘com.XXX.controller.converter.
2022-08-11 07:04:00 【叶不修233】
记录一些遇见的bug——Lombok和Mapstruct的冲突导致,A component required a bean of type 'com.XXX.controller.converter.BrandConverter' that could not be found.
一、问题描述
报错截图:
如果你的项目同时使用了Lombok和Mapstruct工具,写了dto转换类,例如下面的BrandConverter转换类
@Component
@Mapper(componentModel = "spring")
public interface BrandConverter {
PageInfo<BrandDto> toDto(PageInfo<BrandPo> brandPoPageInfo);
}
明明为BrandConverter转换类配置了@Component注解,但idea提示:
A component required a bean of type ‘com.XXX.controller.converter.BrandConverter’ that could not be found.
未找到BrandConverter的bean
二、原因和解决方案
由于 MapStruct 依赖于 JavaBean 中有 getter/setter 方法,所以,如果使用了 lombok 来生成 getter/setter 方法的话,那么在配置上有一些特殊的地方:需要 lombok 先对 .class 文件"动手脚",然后 MapStruct 再来对 .class 文件"动手脚"。
我们需要在 maven 项目的 pom.xml 中的 plugins > plugin 下的 maven-compiler-plugin 插件下加上好大一坨 configuration 配置。
如图所示:
<properties>
<org.mapstruct.version>1.5.0.RC1</org.mapstruct.version>
<org.projectlombok.version>1.18.20</org.projectlombok.version>
<lombok-mapstruct-binding.version>0.2.0</lombok-mapstruct-binding.version>
... 其它版本声明
</properties>
<dependencies>
<!-- lombok dependencies should not end up on classpath -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${org.projectlombok.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>${org.mapstruct.version}</version>
</dependency>
...其它依赖声明
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${org.mapstruct.version}</version>
</path>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${org.projectlombok.version}</version>
</path>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-mapstruct-binding</artifactId>
<version>${lombok-mapstruct-binding.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
...其它插件声明
</plugins>
</build>
clean之后重新编译,再次启动,不再报错。
边栏推荐
- What are the things that should be planned from the beginning when developing a project with Unity?How to avoid a huge pit in the later stage?
- 1096 大美数 (15 分)
- Unity开发者必备的C#脚本技巧
- 1051 复数乘法 (15 分)
- 查找最新人员工资和上上次人员工资的变动情况
- Pinduoduo API interface
- oracle19c不支持实时同步参数,请教一下大佬们有什么好的解决办法吗?
- 1036 Programming with Obama (15 points)
- Discourse's Close Topic and Reopen Topic
- 【软件测试】(北京)字节跳动科技有限公司二面笔试题
猜你喜欢
1002 Write the number (20 points)
go-grpc TSL认证 解决 transport: authentication handshake failed: x509 certificate relies on ... ...
Taobao product details API interface
tf.reduce_mean()与tf.reduce_sum()
1081 检查密码 (15 分)
我的创作纪念日丨感恩这365天来有你相伴,不忘初心,各自精彩
【Pytorch】nn.ReLU(inplace=True)
详述MIMIC 的ICU患者检测时间信息表(十六)
Pinduoduo API interface
DDR4内存条电路设计
随机推荐
How Unity handles C# under the hood
1096 大美数 (15 分)
2022-08-10 mysql/stonedb-慢SQL-Q16-耗时追踪
2.1-梯度下降
Internet phone software or consolidation of attack must be "free" calls security clearance
Find the latest staff salary and the last staff salary changes
梅科尔工作室——BP神经网络
Discourse's Close Topic and Reopen Topic
接入网、承载网、核心网是什么,交换机路由器是什么、这个和网络的协议有什么关系呢?
国密规范 SM2 SM3 SM4
【LeetCode每日一题】——682.棒球比赛
Pinduoduo API interface
分布式锁-Redission - 缓存一致性解决
1091 N-自守数 (15 分)
CIKM 2022 AnalytiCup Competition: 联邦异质任务学习
线程交替输出(你能想出几种方法)
Implementation of FIR filter based on FPGA (5) - FPGA code implementation of parallel structure FIR filter
easyrecovery15数据恢复软件收费吗?功能强大吗?
prometheus学习5altermanager
3.1-Classification-probabilistic generative model