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.

你可能感兴趣的:(Spring - ComponentScan注解中的basePackageClasses)