Spring nullable注释生成未知的枚举常量警告

夢のの*_*のの夢 8 spring spring-boot

在我的应用中,每当我将@Nullable(从中导入org.springframework.lang.Nullable)到任何字段时,都会收到生成警告:

警告:java:未知的枚举常量javax.annotation.meta.When.MAYBE原因:javax.annotation.meta的类文件。

@NonNull以及Spring产生的其他空安全注释不会发出任何警告,因为它的实现并不重要import javax.annotation.meta.When

该应用程序运行正常,但警告很烦人。我正在使用Spring Boot 2.1.0和Java版本1.8.0_191

rii*_*ich 29

此警告是由javax.annotation.meta.When枚举不可用于您的项目运行时引起的(org.springframework.lang.Nullable引用此枚举但它不会自动提供)。您需要引入 JSR305 实现来修复此警告。

Google find bugs repo 包含一个 JSR305 实现,可以解决这个问题:https : //mvnrepository.com/artifact/com.google.code.findbugs/jsr305

由于您使用的是 gradle,请将依赖项添加到您的build.gradle脚本中:

...
dependencies {
    ...

     // https://mvnrepository.com/artifact/com.google.code.findbugs/jsr305
    implementation 'com.google.code.findbugs:jsr305:3.0.2'

    ...
}
...
Run Code Online (Sandbox Code Playgroud)

做一个干净的构建,错误应该消失


如果您不想使用该com.google.code.findbugs组的工件,您可以尝试此列表中的另一个:https : //mvnrepository.com/search?q=JSR305

参考:

  • 仅编译 'com.google.code.findbugs:jsr305:3.0.2' 就足够了 (9认同)

小智 6

我也很烦 只需在pom中尝试一下:

    <dependency>
        <groupId>com.google.code.findbugs</groupId>
        <artifactId>annotations</artifactId>
        <version>3.0.1</version>
    </dependency>
Run Code Online (Sandbox Code Playgroud)

这对我有用。

  • 注意:此工件已移至:com.github.spotbugs » spotbugs-annotations (5认同)