[spring-mvc] <context:component-scan/> <mvc:annotation-driven/>
来源:互联网 发布:网络球机云台设置 编辑:程序博客网 时间:2024/06/06 02:05
<mvc:annotation-driven/>标签
这个标签对应的实现类是org.springframework.scheduling.config.AnnotationDrivenBeanDefinitionParser
仔细阅读它的注释文档可以很明显的看到这个类的作用。解析这个文档:
这个类主要注册8个类的实例:
- RequestMappingHandleMapping
- BeanNameUrlhandlerMapping
- RequestMappingHandlerAdapter
- HttpRequestHandleAdapter
- SimpleControllerHandlerAdapter
- ExceptionHandlerExceptionResolver
- ResponseStatusExceptionResolver
- DefaultHandlerExceptionResolver
1是处理RequestMapping注解的。2将controller类的名字映射为请求url。1和2都实现了HandlerMapping接口,用来处理请求映射。3是处理@Controller注解的控制器类,4是处理继承HttpRequestHandlerAdapter类的控制器类,5处理继承SimpleControllerHandlerAdapter类的控制器。所以这三个是用来处理请求的。具体点说就是确定调用哪个controller的哪个方法来处理当前请求。6,7,8全部继承AbstractHandlerExceptionResolver,这个类实现HandlerException,该接口定义:接口实现的对象可以解决处理器映射、执行期间抛出异常,还有错误的视图。
所以<annotation-driven>
标签主要是用来帮助我们处理请求映射,决定是哪个controller的哪个方法来处理当前请求,异常处理。
<context:component-scan/>
标签:
它的实现类是org.springframework.context.annotation.ComponentScanBeanDefinitionParser。
把鼠标放在context:component-scan上就可以知道有什么作用的,用来扫描该包内被@Repository @Service @Controller的注解类,然后注册到工厂。并且context:component-scan激活@Required @Resource @autowired @PostConstruct @PreDestroy @PersistenceContext @PersistenceUnit。使用在适用该bean的时候用@Autowired就行了。
原文出处
Spring配置 <context:component-scan/> <mvc:annotation-driven />
:http://blog.csdn.net/sunhuwh/article/details/25558867
- [spring-mvc] <context:component-scan/> <mvc:annotation-driven/>
- Spring配置 <context:component-scan/> <mvc:annotation-driven />
- Spring配置 <context:component-scan/> <mvc:annotation-driven />
- spring <context:component-scan />及<mvc:annotation-driven />使用说明
- Spring配置 <context:component-scan/> <mvc:annotation-driven />
- Spring <context:component-scan/>与<mvc:annotation-driven/>
- spring <context:component-scan />及<mvc:annotation-driven />使用说明
- Spring配置 <context:component-scan/> <mvc:annotation-driven />
- 剖析<context:component-scan/>、<mvc:annotation-driven/>
- <context:component-scan/> <mvc:annotation-driven />
- <context:component-scan/> <mvc:annotation-driven /> 区别
- <mvc:annotation-driven/>,<context:annotation-config/>,<context:component-scan/>详解
- <mvc:annotation-driven/> <context:annotation-config/> <context:component-scan>
- Spring <context:annotation-config/> <context:component-scan/>与<mvc:annotation-driven />
- spring mvc 中mvc:annotation-driven和context:component-scan区别
- spring mvc <mvc:annotation-driven/> 和<context:component-scan base-package=""/>解释
- <context:component-scan/>和<mvc:annotation-driven/>的区别
- <context:component-scan/>和<mvc:annotation-driven/>的区别
- codevs1255 搭积木 (记忆化搜索)
- 神经网络(3)
- JavaScript基础之获取及修改元素属性
- C语言计算题--求五十个素数
- MongoDB
- [spring-mvc] <context:component-scan/> <mvc:annotation-driven/>
- Java中的泛型使用
- 118. Pascal's Triangle
- Lintcode52 Next Permutation solution 题解
- Android 开发第一天
- 4. Lucene各种查询操作(Lucene6.0.0)
- Java IO之字节流
- (58)组件之渲染组件
- HDU 2.1.7