我使用 gRPC 生成代码“@javax.annotation.Generate”,如下图所示。
然后我使用maven构建项目,它报告“Error:(20,18) java:cannot find symbol”,如下图所示。
如何解决?
您可以将
javax.annotation-api
依赖项添加到您的 Maven pom.xml
来解析注释。
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.2</version>
</dependency>
就我而言,这是由于在意外安装了太新版本 Java 的系统上构建项目(19 而不是 8)而导致的。在 File -> Project Structure 中将 Java 版本从 19 更改为 8 解决了我的问题。
我的问题涉及在代码库(其中包含 Swagger codegen 文件)下升级我的 Java 平台(JDK8 -> JDK17)。
解决方案是将所有
@javax.annotation.Generated
大规模重构为 @javax.annotation.processing.Generated
。没有依赖性变化。
我也面临类似的项目问题https://github.com/eugenp/tutorials/tree/master/spring-web-modules/spring-rest-query-language.
问题 - 父模块和 spring-rest-query-language 模块的源和目标为 java 8。但我想使用具有 openjdk 21 的 Intellij 运行它。其他模块与 openjdk21 一起正常工作,但此模块显示错误 -
class Generated not found error, javax.annotation.processing Generate not found
解决方案-
2.我已将源和目标更改为 21,如下所示快照(在顶部菜单 -> Intellij IDEA -> 设置 -> 构建、执行、部署 -> java 编译器中)。