Spring <context:component-scan/>与<mvc:annotation-driven/>
来源:互联网 发布:js shift splice 编辑:程序博客网 时间:2024/06/01 09:04
<mvc:annotation-driven/>
开启SpringMVC注解支持,相当于注册了DefaultAnnotationHandlerMapping和AnnotationMethodHandlerAdapter两个bean,配置一些messageconverter。即解决了@Controller注解的使用前提配置。如果没有开启此注解则会显示404找不到页面,就是没有配置视图解析的原因。
<context:component-scan/>
是对包进行扫描,实现注释驱动Bean定义,同时将bean自动注入容器中使用。即解决了@Controller标识的类的bean的注入和使用。 主要作用是将@Component,@Controller,@Service,@Repository等注解生成相应的bean,并且放置到FactoryBean中。
注意:一定要区分Spring与SpringMVC。Spring配置文件中只扫描普通的bean。像@Controller,@RequestMapping是属于SpringMVC的,需要在SpringMVC配置文件中扫描。如果不分开扫描,非常容易导致事物失败。
下面的代码只扫描Spring的bean。
<!-- 启动组件扫描,排除@Controller组件,该组件由SpringMVC配置文件扫描 --> <context:component-scan base-package="com.jxufe.**"> <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/> </context:component-scan>
下面的代码只扫描SpringMVC部分
<!--自动扫描所有的Controller注解 所有的Controller必须放置在controller包下--> <context:component-scan base-package="com.jxufe.**.controller"/>
1 0
- Spring <context:component-scan/>与<mvc:annotation-driven/>
- Spring <context:annotation-config/> <context:component-scan/>与<mvc:annotation-driven />
- [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 />
- 剖析<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 mvc 中mvc:annotation-driven和context:component-scan区别
- spring mvc <mvc:annotation-driven/> 和<context:component-scan base-package=""/>解释
- Spring mvc——接收对象Json数据,<mvc:annotation-driven/><context:annotation-config/><context:component-scan/>
- <context:component-scan/>和<mvc:annotation-driven/>的区别
- xUtils===xUtils3.0基本使用规则
- codeforces 724B Batch Sort
- 关于bootasm.s理解
- 如何选择VPS——已Hostus选择节点为例
- 解决debian7下安装GD扩展失败的问题
- Spring <context:component-scan/>与<mvc:annotation-driven/>
- 2016/10/09 今天真是忙碌的一天啊
- SD卡协议学习(一)
- trie树
- Leetcode 59. Spiral Matrix II (Medium) (java)
- socket学习(3)
- mysql执行外部sql文件
- STL优先队列的优先级
- 智能输入器