<context:component-scan>使用说明

该标签会在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>   
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值