Spring 声纳启动配置问题
Spring boot configuration issues with sonar
'ABCService' 无法通过@ComponentsScan 或@SpringBootApplication 访问。将其移动到在@ComponentsScan 中配置的包或更新您的@ComponentsScan 配置。
这是我在 Sonarqube 分析中的 9 个严重错误中得到的错误消息,每个服务和控制器一个。
尽管@Autowire 和依赖注入工作正常,但 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 具有组件扫描功能,可以扫描主 class 包及其所有子包,所以这个问题不应该出现。
引用 Sonar 的规则,
@ComponentScan is used to determine which Spring Beans are available
in the application context. The packages to scan can be configured
thanks to the basePackageClasses or basePackages (or its alias value)
parameters. If neither parameter is configured, @ComponentScan will
consider only the package of the class annotated with it. When
@ComponentScan is used on a class belonging to the default package,
the entire classpath will be scanned.
This will slow-down the start-up of the application and it is likely
the application will fail to start with an
BeanDefinitionStoreException because you ended up scanning the Spring
Framework package itself.
在 link 下方查找,他们还提到了如何编写兼容代码。
这是一个 SonarQube 错误,它没有正确处理 SpringBootApplication。你应该在这里报告:https://community.sonarsource.com/c/bug
'ABCService' 无法通过@ComponentsScan 或@SpringBootApplication 访问。将其移动到在@ComponentsScan 中配置的包或更新您的@ComponentsScan 配置。
这是我在 Sonarqube 分析中的 9 个严重错误中得到的错误消息,每个服务和控制器一个。
尽管@Autowire 和依赖注入工作正常,但 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 具有组件扫描功能,可以扫描主 class 包及其所有子包,所以这个问题不应该出现。
引用 Sonar 的规则,
@ComponentScan is used to determine which Spring Beans are available in the application context. The packages to scan can be configured thanks to the basePackageClasses or basePackages (or its alias value) parameters. If neither parameter is configured, @ComponentScan will consider only the package of the class annotated with it. When @ComponentScan is used on a class belonging to the default package, the entire classpath will be scanned.
This will slow-down the start-up of the application and it is likely the application will fail to start with an BeanDefinitionStoreException because you ended up scanning the Spring Framework package itself.
在 link 下方查找,他们还提到了如何编写兼容代码。
这是一个 SonarQube 错误,它没有正确处理 SpringBootApplication。你应该在这里报告:https://community.sonarsource.com/c/bug