component-scan和annotation-driven
<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的更多相关文章
- [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 ...
- 注解Annotation的IoC:从@Autowired到@Component
注解Annotation的IoC:从@Autowired到@Component 2017-01-23 目录 1 什么是注解2 不使用注解示例 2.1 com.springioc.animal.Mon ...
- Domain Driven Design and Development In Practice--转载
原文地址:http://www.infoq.com/articles/ddd-in-practice Background Domain Driven Design (DDD) is about ma ...
- Annotation Type @bean,@Import,@configuration使用--官方文档
@Target(value={METHOD,ANNOTATION_TYPE}) @Retention(value=RUNTIME) @Documented public @interface Bean ...
- Spring 一二事(8) - annotation 形式的 MVC
<!-- component:把一个类放入到spring容器中,该类就是一个component 在base-package指定的包及子包下扫描所有的类 --> <context:co ...
- Spring 4 Ehcache Configuration Example with @Cacheable Annotation
http://www.concretepage.com/spring-4/spring-4-ehcache-configuration-example-with-cacheable-annotatio ...
- Java-Class-@I:java.annotation.Resource
ylbtech-Java-Class-@I:java.annotation.Resource 1.返回顶部 2.返回顶部 1.1. import javax.annotation.Resource ...
- 关于 Spring Boot 中创建对象的疑虑 → @Bean 与 @Component 同时作用同一个类,会怎么样?
开心一刻 今天放学回家,气愤愤地找到我妈 我:妈,我们班同学都说我五官长得特别平 妈:你小时候爱趴着睡觉 我:你怎么不把我翻过来呢 妈:那你不是凌晨2点时候出生的吗 我:嗯,凌晨2点出生就爱趴着睡觉呗 ...
- Spring MVC Test -Controller
http://www.petrikainulainen.net/programming/spring-framework/unit-testing-of-spring-mvc-controllers- ...
- 尚硅谷springboot学习5-主入口类说明
package com.atguigu; import org.springframework.boot.SpringApplication; import org.springframework.b ...
随机推荐
- POJ 1389 Area of Simple Polygons | 扫描线
请戳此处 #include<cstdio> #include<algorithm> #include<cstring> #define N 1010 #define ...
- 百度AI开放平台 UNIT平台开发在线客服 借助百度的人工智能如何开发一个在线客服系统
这段时间在研究一些人工智能的产品,对比了国内几家做人工智能在线客服的,有些接口是要收费的,有些是免费的,但是做了很多限制,比如每天调用的接口次数限制是100次.后来就找到了百度的AI,大家也知道,目前 ...
- 模拟Windows系统“回收站”
HTML: <!DOCTYPE html><html> <head> <meta http-equiv="content-type" co ...
- Mysql大数据备份及恢复
<p>[引自攀岩人生的博客]MySQL备份一般采取全库备份.日志备份;MySQL出现故障后可以使用全备份和日志备份将数据恢复到最后一个二进制日志备份前的任意位置或时间;mysql的二进制日 ...
- python自动化测试windows gui
http://sourceforge.net/projects/pywinauto/files/pywinauto/ http://www.microsoft.com/en-us/download/c ...
- cocos2d学习网址
http://python.cocos2d.org/doc/programming_guide/index.html http://bbs.tairan.com/article-25-1.html h ...
- 原 android重启应用(应用重新启动自身)
private void restartApplication() { final Intent intent = getPackageManager().getLaunchIntentForPack ...
- css容器
.s1{ background-color:pink; font-weight:bold; font-size=16px; color:black; } #id1{ background-color: ...
- hdu 5139(离线处理+离散化下标)
Formula Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Sub ...
- git 本地与远程关联流程
git init git add -A git commit -m '提交' git remote add origin git@github.com:laniu/liuna.git git push ...