该标签会在spring配置文件中用到。
spring下的注解:
@Component是所有受Spring管理组件的通用形式;而@Repository、@Service和 @Controller则是@Component的细化,用来表示更具体的用例(例如,分别对应了持久化层、服务层和表现层)。
< context:component-scan>标签的用处?
在xml配置了这个标签后,spring可以自动去扫描base-pack下面或者子包下面的Java文件,如果扫描到有@Component @Controller@Service等这些注解的类,则把这些类注册为bean
用法:
扫描base-package下的所有类:
<context:component-scan base-package="tv.huan.weisp.web ">
如果是想扫描base-package下部分或排除部分,写法如下。其中:use-default-filters="false"表示会在base-package下按照其他条件来扫描类,而不是扫描base-package下的所有类。
<context:exclude-filter>指定的不扫描,<context:include-filter>指定的扫描。
本例中是只扫描base-package下的@Controller类型。
<context:component-scan base-package="tv.huan.weisp.web" use-default-filters="false">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>