Spring nullable注释生成未知的枚举常量警告 [英] Spring nullable annotation generates unknown enum constant warning
问题描述
在我的应用程序中,每当我将@Nullable
(从org.springframework.lang.Nullable
导入)添加到任何字段时,都会收到生成警告:
In my app, whenever I add @Nullable
(which imports from org.springframework.lang.Nullable
) to any of the fields, I get a build warning:
警告:java:未知的枚举常量javax.annotation.meta.When.MAYBE 原因:javax.annotation.meta的类文件.找不到时
Warning:java: unknown enum constant javax.annotation.meta.When.MAYBE reason: class file for javax.annotation.meta.When not found
@NonNull
和其他来自spring的安全性无效注释会在没有任何警告的情况下进行编译,因为其实现不会导入import javax.annotation.meta.When
.
@NonNull
and other null safety annoations from spring compile without any warnings as its implementation doesn't import import javax.annotation.meta.When
.
应用程序运行正常,但警告很烦人.我正在使用Spring Boot 2.1.0
和Java版本1.8.0_191
The application runs just fine but the warning is just annoying. I am using spring boot 2.1.0
and java version 1.8.0_191
推荐答案
此警告是由javax.annotation.meta.When
枚举对您的项目运行时不可用引起的(org.springframework.lang.Nullable
引用了该枚举,但它不会自动变为可用).您需要引入JSR305实现来解决此警告.
This warning is caused by the javax.annotation.meta.When
enum not being available to your projects runtime (org.springframework.lang.Nullable
references this enum but it is not made available automatically). You need to bring in a JSR305 implementation to fix this warning.
Google查找错误存储库包含应该解决该问题的JSR305实现: https://mvnrepository.com/artifact/com.google.code.findbugs/jsr305
the Google find bugs repo includes a JSR305 implementation that should fix the problem: https://mvnrepository.com/artifact/com.google.code.findbugs/jsr305
由于您正在使用gradle,因此请将依赖项添加到build.gradle
脚本中:
since you are using gradle, add the dependency to your build.gradle
script:
...
dependencies {
...
// https://mvnrepository.com/artifact/com.google.code.findbugs/jsr305
implementation 'com.google.code.findbugs:jsr305:3.0.2'
...
}
...
执行干净的构建,错误应该消失
如果您不想使用com.google.code.findbugs
组的工件,则可以尝试以下列表中的另一个工件:
https://mvnrepository.com/search?q=JSR305
If you do not want to use the com.google.code.findbugs
group's artifact you can try another from this list:
https://mvnrepository.com/search?q=JSR305
参考:
- 奇怪的Eclipse IDE错误javax.annotation.meta.When #Java
- Java的@OverridingMethodMustCallSuper发生了什么事情?
- https://github.com/sbrannen/runtime-annotations/blob/master/src/main/java/org/example/SpringApplication.java
- Strange Eclipse IDE error javax.annotation.meta.When #Java
- What happened to Java's @OverridingMethodMustCallSuper?
- https://github.com/sbrannen/runtime-annotations/blob/master/src/main/java/org/example/SpringApplication.java
这篇关于Spring nullable注释生成未知的枚举常量警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!