1.如果不想在xml文件中配置bean,我们可以给我们的类加上spring组件注解,只需再配置下spring的扫描器就可以实现bean的自动载入。

<!-- 注解注入 -->

<context:annotation-config></context:annotation-config>
<context:component-scan base-package="com.liantuo.hotel.common.service.impl" />
<context:component-scan base-package="com.liantuo.hotel.common.dao.ibatis" />
<context:component-scan base-package="com.liantuo.hotel.app.dao.ibatis" />
<context:component-scan base-package="com.liantuo.hotel.app.service" />
<context:component-scan base-package="com.liantuo.hotel.app.service.ibatis" />
2.下面是引用spring framework开发手册中的一段话
Spring 2.5引入了更多典型化注解(stereotype annotations): @Component@Service和 @Controller@Component是所有受Spring管理组件的通用形式;而@Repository@Service和 @Controller则是@Component的细化,用来表示更具体的用例(例如,分别对应了持久化层、服务层和表现层)。也就是说,你能用@Component来注解你的组件类,但如果用@Repository@Service 或@Controller来注解它们,你的类也许能更好地被工具处理,或与切面进行关联。例如,这些典型化注解可以成为理想的切入点目标。当然,在Spring Framework以后的版本中, @Repository@Service和 @Controller也许还能携带更多语义。如此一来,如果你正在考虑服务层中是该用@Component还是@Service,那@Service显然是更好的选择。同样的,就像前面说的那样, @Repository已经能在持久化层中进行异常转换时被作为标记使用了。”
3.有了<context:component-scan>,另一个<context:annotation-config/>标签根本可以移除掉,因为已经被包含进去了。
4.<context:component-scan>提供两个子标签:<context:include-filter>和<context:exclude-filter>各代表引入和排除的过滤。
如:<context:component-scan base-package="com.xhlx.finance.budget" >

<context:include-filter type="regex" expression=".service.*"/>
</context:component-scan>

5.filter标签在Spring3有五个type,如下:
Filter Type Examples Expression Description
annotation org.example.SomeAnnotation 符合SomeAnnoation的target class
assignable org.example.SomeClass 指定class或interface的全名
aspectj org.example..*Service+ AspectJ语法
regex org\.example\.Default.* Regelar Expression
custom org.example.MyTypeFilter Spring3新增自訂Type,实作org.springframework.core.type.TypeFilter

源:http://blog.csdn.net/a9529lty/article/details/8251003

转 Spring 组件 <context:component-scan base-pakage="">用法的更多相关文章

  1. [Spring Boot] Use Component Scan to scan for Bean

    Component Scan is important concept when we want to create Bean. Currently we know what, for the cla ...

  2. Spring组件扫描<context:component-scan/>使用详解

    1.如果不想在xml文件中配置bean,我们可以给我们的类加上spring组件注解,只需再配置下spring的扫描器就可以实现bean的自动载入. <!-- 注解注入 --> <co ...

  3. Spring 学习——Spring常用注解——@Component、@Scope、@Repository、@Service、@Controller、@Required、@Autowired、@Qualifier、@Configuration、@ImportResource、@Value

    Bean管理注解实现 Classpath扫描与组件管理 类的自动检测与注册Bean 类的注解@Component.@Service等作用是将这个实例自动装配到Bean容器中管理 而类似于@Autowi ...

  4. Spring注解之@Component详细解析

    @controller 控制器(注入服务) 2.@service 服务(注入dao) 3.@repository dao(实现dao访问) 4.@component (把普通pojo实例化到sprin ...

  5. 教你写Spring组件

    前言 原文地址:https://www.cnblogs.com/qnlcy/p/15905682.html 一.宗旨 在如日中天的 Spring 架构体系下,不管是什么样的组件,不管它采用的接入方式如 ...

  6. spring 组件@Scope(request,session)示例

    上回说到, spring组件的注解Scope大约有singleton.prototype.request.session.global session 这么几种常用的场景.这里需要特别说明一下,根据源 ...

  7. Spring @Configuration 和 @Component 区别

    Spring @Configuration 和 @Component 区别 一句话概括就是 @Configuration 中所有带 @Bean 注解的方法都会被动态代理,因此调用该方法返回的都是同一个 ...

  8. hibernate 组件(Component)映射

    1.类Teacher public class Teacher { private int id; private String name; private String sex; private A ...

  9. spring中context:property-placeholder/元素 转载

    spring中context:property-placeholder/元素  转载 1.有些参数在某些阶段中是常量 比如 :a.在开发阶段我们连接数据库时的连接url,username,passwo ...

随机推荐

  1. 翻译BonoboService官网的安装教程

    This page covers simple Bonobo Git Server installation. Be sure to check prerequisites page before i ...

  2. 字符串匹配算法系列一:KMP算法原理

    本文主要参考了https://mp.weixin.qq.com/s/rbaPmBejID8-rYui35Snrg的表述,加上部分自己的理解 学习任何算法都要了解该算法解决什么问题?我们看看KMP算法主 ...

  3. 线段树专题—ZOJ1610 Count the Colors

    题意:给一个n,代表n次操作,接下来每次操作表示把[l.r]区间的线段涂成k的颜色当中,l,r,k的范围都是0到8000 分析:事实上就是拿线段树维护一段区间的颜色,整体用到的是线段树的区间更新把,可 ...

  4. 【前端阅读】——《程序员思维修炼》摘记&读后感&思维导图

    前言:这是一本介绍如何用脑的书,并从思维的角度(以程序员为例),介绍如何从新手成为专家.作者带领着读者(我)共同经历一次有关认知科学.神经学.学习和行为理论的旅程,探索人类大脑令人 惊奇的工作的机制, ...

  5. Python setup.py和MANIFEST.in文件

    Setup.py文件 from setuptools import setup from codecs import open # 第三方依赖包及版本号 requires = ['beautifuls ...

  6. C 语言经典100例

    C 语言经典100例 C 语言练习实例1 C 语言练习实例2 C 语言练习实例3 C 语言练习实例4 C 语言练习实例5 C 语言练习实例6 C 语言练习实例7 C 语言练习实例8 C 语言练习实例9 ...

  7. Java千百问_05面向对象(006)_is-a,has-a,like-a是什么

    点击进入_很多其它_Java千百问 1.is-a,has-a,like-a是什么 在面向对象设计的领域里,有若干种设计思路,主要有例如以下三种: is-a.has-a.like-a java中在类.接 ...

  8. 【Excle数据透视表】如何显示/隐藏数据透视表字段列表

    在创建完毕的数据透视表中,若单击数据透视表中任意单元格,即可显示数据透视表字段列表窗格,用户就可以通过弹出的窗格进行字段调整 两种情况需要隐藏数据数据透视表窗格 ①数据透视表已经完成 ②失误关闭窗格 ...

  9. ORACLE schedule job设置

    --创建job begin DBMS_SCHEDULER.CREATE_JOB ( job_name => 'APICALL_LOG_INTERFACE_JOB', job_type => ...

  10. SpringMvc aop before

    1.config.xml配置文件 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans ...