@ComponentsScan 或 @SpringBootApplication 无法访问“ABCService”。将其移动到 @ComponentsScan 中配置的包或更新您的 @ComponentsScan 配置。
这是我在 Sonarqube 分析中收到的 9 个严重错误的错误消息,每个服务和 Controller 都有一个。
尽管 @Autowire 和依赖注入(inject)工作正常,但 Sonar 似乎仍在提示。
导致问题的规则是:
Spring beans should be considered by "@ComponentScan"
Spring beans belonging to packages that are not included in a @ComponentScan configuration will not be accessible in the Spring Application Context. Therefore, it's likely to be a configuration mistake that will be detected by this rule. Note: the @ComponentScan is implicit in the @SpringBootApplication annotation, case in which Spring Boot will auto scan for components in the package containing the Spring Boot main class and its sub-packages.
由于@SpringBootApplication具有组件扫描功能,可以扫描主类包及其所有子包,因此这个问题不应该出现。
最佳答案
这是一个 SonarQube 错误,它无法正确处理 SpringBootApplication。您应该在这里报告:https://community.sonarsource.com/c/bug
关于java - Sonar 的 Spring Boot 配置问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57306616/