java - Sonar : Members of Spring components should be "@Autowired"

标签 java spring sonarqube autowired

最新版本 (4.8.0.9441) 中引入的 SonarJava 分析器等规则 s3749 (Spring 组件的成员应该是“@Autowired”)。事实证明,SONAR 完全排除了场注入(inject)以外的其他 Autowiring 模式,即。 e.构造函数/ setter @Autowired 不会阻止此规则失败。这背后有什么理由吗?

最佳答案

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

该方法还应该检查@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");
}

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

关于java - Sonar : Members of Spring components should be "@Autowired",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43536730/

相关文章:

java - 在将 EJBTransactionRolledbackException 记录到文件之前捕获它

java - 不支持内容类型 'multipart/form-data;boundary=----...;charset=UTF-8'

java - 为什么使用@Query (“” )操作Elasticsearch并报错(org.elasticsearch.common.ParsingException : no [query] registered for [query])

jenkins - Sonarqube PLSQL 自定义规则,用于在 SQL 脚本文件中检测正确的 SQL 终止符分号

java - 从仪表板注销导致错误 404 : requested resource not available

java - SQL : Batching statements with bound variables

java - 魔数问题的解决方案......?

SonarQube 6.x 的 Angular2 插件

java - 如何显示带空格的制表符?

java - jparepository 未在服务中自动连接