<context:component-scan/>

该xml配置作用是启动Spring的组件扫描功能,自动扫描base-package指定的包及其子文件下的java文件,如果扫描到有@controller、@Service、@Repository、@Component等注解的java类,就会将这些类注册为bean。指定的包可以有多个,用分号隔开。
如果指定了<context:component-scan/>就不用指定<context:annotation-config/>,前者包含后者。使用示例如下:
<context:component-scan base-package="com.ouym.base" use-default-filters="false"><!-- base-package 如果多个,用“,”分隔 -->
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
base-package指定需要扫描的包,include-filter指定需要扫描的注解,上述配置的意思是扫描com.ouym.base包下的@controller注解的java文件。

而<context:annotation-config/>的实际作用是向spring容器注入以下几个类:AutowiredAnnotationBeanPostProcessor、CommonAnnotationBeanPostProcessor、PersistenceAnnotationBeanPostProcessor 及RequiredAnnotationBeanPostProcessor 四个beanPostProcessor。这些类的作用主要是使一些注解生效,详细请自行查阅。

<mvc:annotation-driver/>

在spring中一般采用@RequestMapping注解来完成映射关系,要想使@RequestMapping注解生效必须向上下文中注册DefaultAnnotationHandlerMapping和一个AnnotationMethodHandlerAdapter实例,这两个实例分别在类级别和方法级别处理。而annotation-driven配置帮助我们自动完成上述两个实例的注入。

该注解要和扫描controller的注解一起放在spring主配置文件。

component-scan和annotation-driven的更多相关文章

  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. 注解Annotation的IoC:从@Autowired到@Component

    注解Annotation的IoC:从@Autowired到@Component 2017-01-23 目录 1 什么是注解2 不使用注解示例  2.1 com.springioc.animal.Mon ...

  3. Domain Driven Design and Development In Practice--转载

    原文地址:http://www.infoq.com/articles/ddd-in-practice Background Domain Driven Design (DDD) is about ma ...

  4. Annotation Type @bean,@Import,@configuration使用--官方文档

    @Target(value={METHOD,ANNOTATION_TYPE}) @Retention(value=RUNTIME) @Documented public @interface Bean ...

  5. Spring 一二事(8) - annotation 形式的 MVC

    <!-- component:把一个类放入到spring容器中,该类就是一个component 在base-package指定的包及子包下扫描所有的类 --> <context:co ...

  6. Spring 4 Ehcache Configuration Example with @Cacheable Annotation

    http://www.concretepage.com/spring-4/spring-4-ehcache-configuration-example-with-cacheable-annotatio ...

  7. Java-Class-@I:java.annotation.Resource

    ylbtech-Java-Class-@I:java.annotation.Resource 1.返回顶部   2.返回顶部 1.1. import javax.annotation.Resource ...

  8. 关于 Spring Boot 中创建对象的疑虑 → @Bean 与 @Component 同时作用同一个类,会怎么样?

    开心一刻 今天放学回家,气愤愤地找到我妈 我:妈,我们班同学都说我五官长得特别平 妈:你小时候爱趴着睡觉 我:你怎么不把我翻过来呢 妈:那你不是凌晨2点时候出生的吗 我:嗯,凌晨2点出生就爱趴着睡觉呗 ...

  9. Spring MVC Test -Controller

    http://www.petrikainulainen.net/programming/spring-framework/unit-testing-of-spring-mvc-controllers- ...

  10. 尚硅谷springboot学习5-主入口类说明

    package com.atguigu; import org.springframework.boot.SpringApplication; import org.springframework.b ...

随机推荐

  1. redis cluster管理工具redis-trib.rb详解

    redis cluster管理工具redis-trib.rb详解 来源 http://weizijun.cn/2016/01/08/redis%20cluster%E7%AE%A1%E7%90%86% ...

  2. 堆栈(Stacks)

    堆栈(Stacks) 准备工作 安装Docker 1.13及以上版本 安装Docker Compose正如第三部分的准备工作. 安装Docker Machine正如第四部分的准备工作. 阅读第一部分的 ...

  3. div样式

    DIV样式汇总 一.常用属性: 1.Height:设置DIV的高度. 2.Width:设置DIV的宽度. 例: <div style="width:200px;height:200px ...

  4. 微信2种access_token对比

    1.需求 了解网页accesstoken和基础accesstoken的不同 参考资料:http://www.cnblogs.com/wellsoho/p/5089409.html

  5. a标签打电话

    <a href="tel:0147-88469258"></a> <a href="mailto:bd@pangxiekeji.com&qu ...

  6. WCF回调操作

    <?xml version="1.0" encoding="utf-8" ?> <configuration> <system.s ...

  7. WireShark:TCP三次握手 抓包

    本机ip:192.168.201.200 服务器ip:192.168.230.20 抓到的数据如下: 第一次握手: SYN标记位为1,表示这是一个连接请求.seq 用于服务端返回确认信息,此时ack ...

  8. touchSlider插件案例

    <!doctype html> <html lang="en"> <head> <title>jQuery手机图片触屏滑动轮播效果代 ...

  9. Linux 设备驱动--- Poll 方法 --- Select【转】

    转自:http://blog.csdn.net/yikai2009/article/details/8653842 版权声明:本文为博主原创文章,未经博主允许不得转载.   目录(?)[-] Sele ...

  10. 配置和读取INI

    #define MAX_FILE_PATH 260 void CControlDlg::OnBnClickedBtnGamepath() { // TODO: 在此添加控件通知处理程序代码 CFile ...