当前位置:网站首页>记录一些遇见的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之后重新编译,再次启动,不再报错。
边栏推荐
- SQL sliding window
- 恒源云-Pycharm远程训练避坑指南
- Pytorch模型转ONNX模型
- tf中矩阵乘法
- 1056 组合数的和 (15 分)
- About # SQL problem: how to set the following data by commas into multiple lines, in the form of column display
- [Recommender System]: Overview of Collaborative Filtering and Content-Based Filtering
- Distributed Lock-Redission - Cache Consistency Solution
- 1096 大美数 (15 分)
- 1091 N-自守数 (15 分)
猜你喜欢
1091 N-自守数 (15 分)
How to choose professional, safe and high-performance remote control software
3.1-Classification-probabilistic generative model
Tensorflow中使用tf.argmax返回张量沿指定维度最大值的索引
DDR4内存条电路设计
1071 小赌怡情 (15 分)
Edge provides label grouping functionality
matrix multiplication in tf
Test cases are hard?Just have a hand
Tf中的平方,多次方,开方计算
随机推荐
【Pytorch】nn.ReLU(inplace=True)
【Pytorch】nn.Linear,nn.Conv
Production and optimization of Unity game leaderboards
1101 B是A的多少倍 (15 分)
欢迎加入sumarua网络安全交流社区
项目2-年收入判断
Serverless + domain name can also build a personal blog? Really, and soon
计算YUV文件的PSNR与SSIM
Dynamic Agent Learning
1096 big beautiful numbers (15 points)
2022-08-10 mysql/stonedb-slow SQL-Q16-time-consuming tracking
js判断图片是否存在
Unity开发者必备的C#脚本技巧
3.2 - classification - Logistic regression
1.1-回归
TF中的条件语句;where()
从何跟踪伦敦金最新行情走势?
Depth (relay supervision)
js根据当天获取前几天的日期
【sdx62】XBL设置共享内存变量,然后内核层获取变量实现