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. 聊聊、Zookeeper API

    今天我们来说说 Zookeeper 客户端启动,整个文章分三个部分:第一部分是 Zookeeper 原生 API 客户端,第二部分是开源客户端 ZkClient,第三部分是开源客户端 Curator. ...

  2. Jsp2.0自定义标签(第一天)——一个简单的例子

    今天是学习自定义标签的第一天 Jsp2.0以来,自定义标签的实现比传统标签的实现容易了很多,一般只要extends类SimpleSupport重写doTag()方法即可. 先看最简单的例子,输出一个H ...

  3. IDEA使用Maven打包时如何去掉测试阶段

    如图

  4. 时间迭代和BigDecimal操作

    常规小操作的代码: import java.math.BigDecimal; import java.sql.Timestamp; import java.text.SimpleDateFormat; ...

  5. JAVA Eclipse创建Android程序界面不显示怎么办

    一般是由于你创建的Android应用程序版本太高导致的,请设置4或以下版本,对于已有的项目,可以在属性-Android中修改目标生成的版本号                               ...

  6. iOS 应用内跳转到系统设置

    在iOS5下面版本号使用下面方法:[IOS5.1+之后不能使用此方法.iOS8的跳转方法已找到见下方,iOS7的正在摸索,欢迎大家给出观点意见] 通过URL Scheme的方式打开内置的Setting ...

  7. HashSet和SortSet对比--c#学习笔记

    微软在 .NET 3.5 新增了一个 HashSet 类,在 .NET 4 新增了一个 SortedSet 类. .NET Collection 函数库的 HashSet.SortedSet 这两个泛 ...

  8. HDOJ--2112--

    HDU Today Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  9. 谈 API 的撰写 - 总览

    背景 之前团队主要的工作就是做一套 REST API.我接手这个工作时发现那些API写的比较业余,没有考虑几个基础的HTTP/1.1 RFC(2616,7232,5988等等)的实现,于是我花了些时间 ...

  10. LeetCode 206 Reverse Linked List(反转链表)(Linked List)(四步将递归改写成迭代)(*)

    翻译 反转一个单链表. 原文 Reverse a singly linked list. 分析 我在草纸上以1,2,3,4为例.将这个链表的转换过程先用描绘了出来(当然了,自己画的肯定不如博客上面精致 ...