Spring - ComponentScan注解中的basePackageClasses

ComponentScan注解里有两种方式用来指定扫描的范围:

  1. scanBasePackages (常用)
    可以指定多个包名进行扫描

2.scanBasePackageClasses
可以指定多个类或接口的class,扫描时会 在这些指定的类和接口所属的包进行扫面。

在stackoverflow上有下面的理由去使用scanBasePackageClasses:

  1. Seems sensible for all such classes to have the same name so they can be easily identified.
  2. Seems sensible for it to start with "Package" (in the same way as package-info.java).
  3. Seems sensible for it to end with "Marker" since the documentation refers to a "marker class".
  4. Opted not to include the word "Base" so it isn't confused with base classes.
  5. Opted not to include the word "Info" as it doesn't contain any info like package-info.java does.
  6. Opted not to include any other words (e.g. "NoOp") to keep it snappy and flexible for other possible uses.
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容