@ComponentScan(Spring 框架提供)
组件扫描器,默认情况下 会扫描当前类 root package 下面的所有对象 并完成关系的建立。
而我之前一直是自己定义了value值.
需要注意的是,这里的@SpringBootApplication自带@ComponentScan
@Target({ElementType.TYPE})@Retention(RetentionPolicy.RUNTIME)@Documented@Inherited@SpringBootConfiguration@EnableAutoConfiguration@ComponentScan( excludeFilters = {@Filter( type = FilterType.CUSTOM, classes = {TypeExcludeFilter.class})})
public @interface SpringBootApplication { Class<?>[] exclude() default {}; String[] excludeName() default {}; @AliasFor( annotation = ComponentScan.class, attribute = "basePackages" ) String[] scanBasePackages() default {}; @AliasFor( annotation = ComponentScan.class, attribute = "basePackageClasses" ) Class<?>[] scanBasePackageClasses() default {};}以上就是他继承的接口。
@SpringBootApplication@MapperScan("org.sselab.mapper")public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); }} 而@MapperScan的用法和他不一样,需要指定包的名称。!
时间: 2024-11-10 21:00:34