Java配置方式
- 编写注解类自定义注解
@Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) public @interface AvoidScan {}
- 启动类对ComponentScan配置
@ComponentScan(excludeFilters = { @ComponentScan.Filter( type = FilterType.ANNOTATION, value = AvoidScan.class) })
- 编写业务类
@VoidScan @Configuration public clsss TestConfiguration{ }
XML配置方式
- 指定具体类不扫描
<context:component-scan base-package="com.yicj.study"> <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" /> <context:exclude-filter type="annotation" expression="org.springframework.web.bind.annotation.RestController" /> <context:exclude-filter type="regex" expression="com.yicj.study.config.*" /> <context:exclude-filter type="assignable" expression="com.yicj.study.servic.UserService"/> </context:component-scan>