SONAR:Spring 组件的成员应该是“@Autowired”

Mar*_*ski 5 java spring autowired sonarqube

最新版本 (4.8.0.9441) 中引入的 SonarJava 分析器以及其他规则s3749Spring 组件的成员应为 "@Autowired")。事实证明,SONAR 完全排除了除字段注入之外的其他自动装配模式,即构造函数/设置器 @Autowired 不会阻止此规则失败。这背后有什么道理吗?

Sta*_*avL 0

看起来是一个错误的规则。

该方法还应该检查@Component

private static boolean isSpringComponent(SymbolMetadata clazzMeta) {
    return clazzMeta.isAnnotatedWith("org.springframework.stereotype.Controller")
      || clazzMeta.isAnnotatedWith("org.springframework.stereotype.Service")
      || clazzMeta.isAnnotatedWith("org.springframework.stereotype.Repository");
}
Run Code Online (Sandbox Code Playgroud)

也可能存在带有@Value("${some.property}"等注释的字段的情况。