Spring配置 <context:component-scan/> <mvc:annotation-driven />
2016-08-18 11:56
483 查看
<annotaion-driven/>标签:
这个标签对应的实现类是org.springframework.web.servlet.config.AnnotationDrivenBeanDefinitionParser
仔细阅读它的注释文档可以很明显的看到这个类的作用。解析这个文档:
这个类主要注册8个类的实例:
1.RequestMappingHandlerMapping
2.BeanNameUrlHandlerMapping
3.RequestMappingHandlerAdapter
4.HttpRequestHandlerAdapter
5.SimpleControllerHandlerAdapter
6.ExceptionHandlerExceptionResolver
7.ResponseStatusExceptionResolver
8.DefaultHandlerExceptionResolver
1是处理@RequestMapping注解的,2.将controller类的名字映射为请求url。1和2都实现了HandlerMapping接口,用来处理请求映射。
3是处理@Controller注解的控制器类,4是处理继承HttpRequestHandlerAdapter类的控制器类,5.处理继承SimpleControllerHandlerAdapter类的控制器。所以这三个是用来处理请求的。具体点说就是确定调用哪个controller的哪个方法来处理当前请求。
6,7,8全部继承AbstractHandlerExceptionResolver,这个类实现HandlerExceptionResolver,该接口定义:接口实现的对象可以解决处理器映射、执行期间抛出的异常,还有错误的视图。
所以<annotaion-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就行了。
这个标签对应的实现类是org.springframework.web.servlet.config.AnnotationDrivenBeanDefinitionParser
仔细阅读它的注释文档可以很明显的看到这个类的作用。解析这个文档:
这个类主要注册8个类的实例:
1.RequestMappingHandlerMapping
2.BeanNameUrlHandlerMapping
3.RequestMappingHandlerAdapter
4.HttpRequestHandlerAdapter
5.SimpleControllerHandlerAdapter
6.ExceptionHandlerExceptionResolver
7.ResponseStatusExceptionResolver
8.DefaultHandlerExceptionResolver
1是处理@RequestMapping注解的,2.将controller类的名字映射为请求url。1和2都实现了HandlerMapping接口,用来处理请求映射。
3是处理@Controller注解的控制器类,4是处理继承HttpRequestHandlerAdapter类的控制器类,5.处理继承SimpleControllerHandlerAdapter类的控制器。所以这三个是用来处理请求的。具体点说就是确定调用哪个controller的哪个方法来处理当前请求。
6,7,8全部继承AbstractHandlerExceptionResolver,这个类实现HandlerExceptionResolver,该接口定义:接口实现的对象可以解决处理器映射、执行期间抛出的异常,还有错误的视图。
所以<annotaion-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 />
- Spring配置 <context:component-scan/> <mvc:annotation-driven />
- Spring配置文件详解:<context:annotation-config/>和<context:component-scan base-package=""/>和<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:annotation-config/>和<context:component-scan base-package=""/>和<mvc:annotati...
- Spring <context:component-scan/>与<mvc:annotation-driven/>
- spring mvc <mvc:annotation-driven/> 和<context:component-scan base-package=""/>解释
- Spring <context:annotation-config/> <context:component-scan/>与<mvc:annotation-driven />
- <context:annotation-config/>,<context:component-scan/>,<mvc:annotation-driven/>区分
- <context:component-scan/>和<mvc:annotation-driven/>的区别
- spring配置中<context:annotation-config> 和 <context:component-scan>区别
- spring注解配置<mvc:annotation-driven />与<context:annotation-config />区别
- 请教<context:component-scan/>和<mvc:annotation-driven/>的区别20
- spring配置中<context:annotation-config> 和 <context:component-scan>区别
- Spring注解之xml配置中的<context:component-scan />和<context:annotation-config/>
- <mvc:annotation-driven/>、<context:component-scan base-package=""/>、<context:annotation-config/>的用法
- <mvc:annotation-driven >和<context:component-scan>
- <mvc:annotation-driven/>、<context:component-scan base-package=""/>、<context:annotation-config/>的用法