我将我的项目从 Spring boot 1.5 迁移到 Spring boot 2。
这样做之后,我在实现@NotNull注释的每个字段上都有一个Misorted修饰符@NotNull private
(来自javax.validation.constraints.*
)。当切换回分支时,此警告消失至 1.5
我尝试禁用 intelij 上的所有插件并删除代码样式和检查的自定义配置。 在搜索此类错误的警告时找到的唯一有效信息是,说明 Intelij 正在采用“java 语言规范”,但在研究这些信息时,似乎它仍然应该是注释后跟修饰符,而不是相反。 (https://docs.oracle.com/javase/specs/jls/se11/html/jls-8.html#jls-8.3.1)
// This does not give a warning
private @NotNull String myString1;
// This does give a warning, wanting me to reformat to the one above
@NotNull
private String myString2;
我想保留第二个示例中的格式,它比上面的更具可读性。当然,当使用多个字段时。
最佳答案
从 Java 8 开始,引入了 TYPE_USE Annotation.Element_type,这改变了注释的使用方式(及其行为方式)。正因为如此,它现在的格式有所不同 简短描述可以在这里找到:https://dzone.com/articles/java-8-type-annotations 。升级到 Spring boot 2 我也更新了
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.1.0.Final</version>
</dependency>
至
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.x.x</version>
</dependency>
显然,在使用 spring boot 依赖项时,这已经改变了:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
长话短说:我们必须习惯使用 TYPE_USE 和 TYPE_PARAMETER ElementTypes 进行注释
我只是不得不花更多时间搜索,出于沮丧在这里问它......
关于java - 自从迁移到 Spring Boot 2 以来,注释上的修饰符出现了错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58061535/