现象
IDEA中的springboot工程,引入了依赖Lombok,配置
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
<profiles>
<profile>dev</profile>
</profiles>
</configuration>
</plugin>
</plugins>
</build>
maven命令(mvn xxx)都正常,@Slf4j注解的类会自动生成 log变量,变量无红线
但是IDEA的build命令,报错找不到log,之所以发现这个是我右击了@Test注解的测试方法
java: 找不到符号
符号: 变量 log
位置: 类 com.mz502.springdemo.service.MyDemoService
解决方案
第一步
- File → Settings → Build, Execution, Deployment → Compiler → Annotation Processors
- 勾选 “Enable annotation processing”
- 选择 “Obtain processors from project classpath”
第二步(有可能不需要)
- File → Settings → Build, Execution, Deployment → Build Tools → Maven → Runner
- 勾选 “Delegate IDE build/run actions to Maven”
原理还没特别明确,我觉得是IDEA自己编译与Maven编译存在差异,我更倾向于都交给Maven

1347

被折叠的 条评论
为什么被折叠?



