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>