zoukankan      html  css  js  c++  java
  • 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主配置文件。

    转载于:https://www.cnblogs.com/ouym/p/7654888.html
  • 相关阅读:
    shell test条件判断
    shell 变量
    shell 流程结构
    shell 正则表达式
    shell脚本常用参数
    snmp 简单的网络管理协议
    linux
    nmap
    git 基础操作
    linux 下 svn 更新代码
  • 原文地址:https://www.cnblogs.com/AbnerRao/p/12875752.html
Copyright © 2011-2022 走看看