zoukankan      html  css  js  c++  java
  • spring和springMVC配置文件中的扫描包如何配置

    原文链接:https://blog.csdn.net/weixin_43802688/article/details/90600611

    我的项目大概文件路径:

    然后进入主题:
    spring的配置文件名称为applicationContext.xml
    springMVC的配置文件名称为dispatcherServlet-servlet.xml

    1.spring的配置文件中需要将Controller的注解排除掉。也就是排除@Controller。需要扫描到service和dao层的注解
    可以用以下这种方式:

    <context:component-scan base-package="com.dancer.crudr">
    <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
    </context:component-scan>
     
    2.springMVC的配置文件中需扫描Controller的注解。也就是扫描@Controller
    可以用以下这种方式:

    <context:component-scan base-package="com.dancer.crud" use-default-filters="false">
    <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
    </context:component-scan>
     
    接下来具体分析:

    //这个是格式,照抄就完了
    <context:component-scan></context:component-scan>
     
    //这个是要扫描的包,我是没填写完整路径
    base-package
     
    //这个默认是true,意思就是会自动对 @Component、@ManagedBeuse-default-filters="true"an、@Named注解的Bean进行扫描。
    反之把他改为false则不对@Component、@ManagedBeuse-default-filters="true"an、@Named注解的Bean进行扫描
    use-default-filters
     
    //这个是排除的意思
    exclude-filter
     
    //这个是包含的意思
    include-filter
     
    spring分析:

    //自动扫描com.dancer.crudr包下的所有注解
    <context:component-scan base-package="com.dancer.crudr">
    //但是排除Controller的注解
    <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
    //exclude-filter:排除,得到除Controller以外的注解
    </context:component-scan>
     


    springMVC分析:

    //不会自动扫描com.dancer.crudr包下的所有注解,因为use-default-filters改为false
    <context:component-scan base-package="com.dancer.crud" use-default-filters="false">
    //获取Controller的注解
    <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
    //use-default-filters:不会自自动扫描
    //include-filter:包含,得到Controller的注解
    </context:component-scan>
    ————————————————
    版权声明:本文为CSDN博主「茂念」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。

  • 相关阅读:
    ReentrantLock和synchronized区别和联系?
    从上向下打印二叉树
    字符串的全排列
    二叉树中和为某一值得路径 java实现
    三大框架面试题
    SQL语句总结
    [terry笔记]Oracle10g/11g安装-redhat5.5
    [terry笔记]Oracle会话追踪(二):TKPROF
    [terry笔记]Oracle会话追踪(一):SQL_TRACE&EVENT 10046
    [terry笔记]IMPDP报错ORA-39083 Object type TYPE failed to create ORA-02304
  • 原文地址:https://www.cnblogs.com/kelelipeng/p/15503803.html
Copyright © 2011-2022 走看看