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版权协议,转载请附上原文出处链接及本声明。

  • 相关阅读:
    【LeetCode】542.01矩阵(Bfs+动态规划,java实现)
    关于BCT,你需要知道的是...
    资源放送丨数据安全:Oracle多场景下比特币勒索的揭密与恢复实战
    3场直播丨达梦DM8数据库安装部署初体验、新基建下的国产数据库应用和发展趋势、Oracle外部表创建与使用...
    数据平台的4个阶段:从数据库到数仓再到中台,超详细的架构全解
    创建九九乘法表
    js变量提升函数提升
    js字符串强转
    js数值强转
    script的src属性能实现跨越访问
  • 原文地址:https://www.cnblogs.com/kelelipeng/p/15503803.html
Copyright © 2011-2022 走看看