美文网首页我爱编程
Spring - ComponentScan注解中的basePa

Spring - ComponentScan注解中的basePa

作者: 爱蛇 | 来源:发表于2018-04-07 17:15 被阅读0次

    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注解中的basePa

        本文链接:https://www.haomeiwen.com/subject/zcvyhftx.html