最新版本 (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/