SpringMvc 之自动注解

<context:component-scan/> 元素会扫描指定的包极其所有子包,并查找能够自动注册为Spring Bean的类.base-package属性标识了<context:component-scan/> 元素所扫描的包

<context:component-scan base-package="org.test">
        <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service" />
    </context:component-scan>

会自动检测的标注Bean

@Component ---通用构造型注解

@Controller--标识为 spring mvc 控制器

@Repository --标识为数据仓储

@Service--标识为服务

过滤组件扫描

过滤器组件

<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service" />---不需要注册为bean

原文地址:https://www.cnblogs.com/ilooking/p/5154271.html