在最新版本(4.8.0.9441)中引入的SonarJava分析器,以及规则s3749 ( Spring的成员应该是"@Autowired")。事实证明,声纳完全排除了场注入以外的其他自动装配模式,即构造函数/setter @Autowired并不能防止这条规则失败。这背后有甚麽理据?
发布于 2017-04-21 07:59:43
看上去是个错误的规则。
方法还应该检查@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}"注释的字段的情况。
https://stackoverflow.com/questions/43536730
复制相似问题