您的位置:首页 > 其它

<mvc:annotation-driven/>、<context:component-scan base-package=""/>、<context:annotation-config/>的用法

2016-03-29 14:19 459 查看
  在Spring中<context:annotation-config/>表示在自动装配时,我们可以使用注解的方式 例如:@Autowired,但是此时在xml文件中仍需要bean配置,只不过此时代替了bean的property

        <context:component-scan base-package=""/>表示扫描指定的包,将注解的类注册为spring容器中的bean,那么此时我们在xml文件中就不需要定义bean,实现xml文件的零配置

     <mvc:annotation-driven/>表示在SpringMVC中注册了DefaultAnnotationHandlerMapping与AnnotationMethodHandlerAdapter 两个bean,表示为@controller、@requestMapping做好准备工作,但是
此时被注解的bean并没有被加入到spring容器中,此时需要用<context:component-scan base-package=""/>扫描并注册bean,因此我们在SpringMVC中出现将<mvc:annotation-driven/>、<context:component-scan
base-package=""/>一起使用。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  mvc