<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. ndk开发-ffmpeg编译

    进入模拟器shell: D:\Users\zhouhaitao\AppData\Local\Android\sdk\platform-tools\adb shell ndk编译链接静态库: LOCAL ...

  2. [poj] 3977 Subset || 折半搜索MITM

    原题 给定N个整数组成的数列(N<=35),从中选出一个子集,使得这个子集的所有元素的值的和的绝对值最小,如果有多组数据满足的话,选择子集元素最少的那个. n<=35,所以双向dfs的O( ...

  3. 《c程序设计语言》-3.2 字符串转换

    #include <stdio.h> #define Num 1000 int main() { int i = 0,j,k,count2 = 0; char s[Num] = {'\0' ...

  4. PEP8特性

    Python 的代码风格由 PEP 8 描述.这个文档描述了 Python 编程风格的方方面面.在遵守这个文档的条件下,不同程序员编写的 Python 代码可以保持最大程度的相似风格.这样就易于阅读, ...

  5. 【ZOJ4070】Function and Function(签到)

    题意:求 k 层嵌套的 f(x) 0<=x,k<=1e9 思路:迭代不会很多次后函数里就会=0或者1,再看层数奇偶直接返回答案 #include<cstdio> #includ ...

  6. C++ delete 两次

    转载自:http://blog.csdn.net/jxluofeng/article/details/19766801 <问题>危险的代码: int* p=new int(1);   de ...

  7. VMWare虚拟机如何与主机共享文件夹(最容易看懂的讲解)附图~

    http://wenku.baidu.com/view/54ab9e19227916888486d776.html 新建好虚拟机并安装好系统后,在编辑虚拟机设置--选项进行以下设置: 点添加 选择你要 ...

  8. Appium+python自动化12-appium元素定位【转载】

    前言 appium定位app上的元素,可以通过id,name.class这些属性定位到 一.id定位 1.appium的id属性也就是通过UI Automator工具查看的resource-id属性

  9. 清明小长假之VUE.JS学习测试码

    我们放了四天假,刚好借此机会,系统的了解一下VUE.JS. <!DOCTYPE html> <html> <head> <meta charset=" ...

  10. 以最简单的方式了解--Github

    大概是从寒假的时候开始正式的赚取github,从github上面学习一些开源的文档,我记得我注册github账号到现在已经9个月了,但只有最近的2个月才发现github这个新世界,写这篇文章是为了刚入 ...