程序员社区

【Spring学习及总结14】context:exclude-filter 和 context:include-filter

文章目录

    • context:exclude-filter
    • context:include-filter

import org.springframework.stereotype.Controller;
@Controller("book")
public class BookController {
}
package com.hh.service;
@Service
public class BookService {
}

context:exclude-filter

指定扫描包时要排除的类:
方式一: type="annotation"按照注解排除,标注了指定注解的组件不要扫描

<context:component-scan base-package="com.hh">
   <!--
   type="annotation":按照注解进行排除,标注了指定注解的组件不要扫描
   expression:注解的全类名
   -->
   <context:exclude-filter
           type="annotation"
           expression=" org.springframework.stereotype.Controller"/>
</context:component-scan>

方式二:
type=“assignable” :指定排除某个具体的类,按照类排除

<context:component-scan base-package="com.hh">
  <!-- 
         type="assignable" :指定排除某个具体的类,按照类排除
         expression:类的全类名
  -->
  <context:exclude-filter 
          type="assignable" 
          expression="com.hh.service.BookService"/>
</context:component-scan>

context:include-filter

指定扫描时要包含的类

<context:component-scan base-package="com.hh" use-default-filters="false">
    <!--
    指定只扫描哪些组件,默认是全都扫描进来
    所以需要设置use-default-filters="false"
    -->
    <context:include-filter 
            type="annotation"
            expression="org.springframework.stereotype.Controller"/>
</context:component-scan>

赞(0) 打赏
未经允许不得转载:IDEA激活码 » 【Spring学习及总结14】context:exclude-filter 和 context:include-filter

相关推荐

  • 暂无文章

一个分享Java & Python知识的社区