ComponentScan注解里有两种方式用来指定扫描的范围:
- scanBasePackages (常用)
可以指定多个包名进行扫描
2.scanBasePackageClasses
可以指定多个类或接口的class,扫描时会 在这些指定的类和接口所属的包进行扫面。
在stackoverflow上有下面的理由去使用scanBasePackageClasses:
- Seems sensible for all such classes to have the same name so they can be easily identified.
- Seems sensible for it to start with "Package" (in the same way as package-info.java).
- Seems sensible for it to end with "Marker" since the documentation refers to a "marker class".
- Opted not to include the word "Base" so it isn't confused with base classes.
- Opted not to include the word "Info" as it doesn't contain any info like package-info.java does.
- Opted not to include any other words (e.g. "NoOp") to keep it snappy and flexible for other possible uses.
网友评论