当前位置:网站首页>记录一些遇见的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之后重新编译,再次启动,不再报错。
边栏推荐
- Activity的四种启动模式
- TF通过feature与label生成(特征,标签)集合,tf.data.Dataset.from_tensor_slices
- 2.1 - Gradient Descent
- TF generates (feature, label) set through feature and label, tf.data.Dataset.from_tensor_slices
- 从何跟踪伦敦金最新行情走势?
- 易观分析联合中小银行联盟发布海南数字经济指数,敬请期待!
- 线程交替输出(你能想出几种方法)
- How do you optimize the performance of your Unity project?
- 1101 B是A的多少倍 (15 分)
- Depth (relay supervision)
猜你喜欢
TF generates (feature, label) set through feature and label, tf.data.Dataset.from_tensor_slices
The most complete documentation on Excel's implementation of grouped summation
Project 1 - PM2.5 Forecast
Interaction of Pico neo3 in Unity
2.1 - Gradient Descent
【Pytorch】nn.PixelShuffle
My creative anniversary丨Thank you for being with you for these 365 days, not forgetting the original intention, and each is wonderful
Decrement operation in tf; tf.assign_sub()
3.1-Classification-probabilistic generative model
1003 我要通过 (20 分)
随机推荐
接口测试的基础流程和用例设计方法你知道吗?
SQL sliding window
Use tf.argmax in Tensorflow to return the index of the maximum value of the tensor along the specified dimension
Pico neo3 Unity打包设置
redis操作
1071 Small Gamble (15 points)
Item 2 - Annual Income Judgment
Discourse's Close Topic and Reopen Topic
1061 判断题 (15 分)
3.2-分类-Logistic回归
查找最新人员工资和上上次人员工资的变动情况
matplotlib
Implementation of FIR filter based on FPGA (5) - FPGA code implementation of parallel structure FIR filter
1.1-回归
tf中自减操作;tf.assign_sub()
About # SQL problem: how to set the following data by commas into multiple lines, in the form of column display
1091 N-自守数 (15 分)
Redis source code: how to view the Redis source code, the order of viewing the Redis source code, the sequence of the source code from the external data structure of Redis to the internal data structu
Decrement operation in tf; tf.assign_sub()
动态代理学习