问题描述
在使用springboot 3.0 版本以及之后的版本过程中,有可能会遇到 lombok注解失效的问题,报错如下:xxx找不到符号
原因分析:
新版本的 springboot 版本把 lombok 的依赖标注成了 optional ,这会导致 maven 认为该依赖是可选的,在项目编译的时候就不会被加载,从而抛出异常。
解决方案:
在pom.xml文件中的 built 标签的 plugins 标签下手动添加 lombok版本号,注意标签是:
<artifactId>maven-compiler-plugin</artifactId>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<!-- 在这里手动添加lombok版本号-->
<version>1.18.22</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
或者直接把这一部分给全部注释掉:
<!-- <plugin>-->
<!-- <groupId>org.apache.maven.plugins</groupId>-->
<!-- <artifactId>maven-compiler-plugin</artifactId>-->
<!-- <configuration>-->
<!-- <annotationProcessorPaths>-->
<!-- <path>-->
<!-- <groupId>org.projectlombok</groupId>-->
<!-- <artifactId>lombok</artifactId>-->
<!--<!– 在这里手动添加lombok版本号–>-->
<!-- <version>1.18.22</version>-->
<!-- </path>-->
<!-- </annotationProcessorPaths>-->
<!-- </configuration>-->
<!-- </plugin>-->