zoukankan      html  css  js  c++  java
  • Spring组件扫描<context:component-scan/>使用详解

    1.如果不想在xml文件中配置bean,我们可以给我们的类加上spring组件注解,只需再配置下spring的扫描器就可以实现bean的自动载入。

    <!-- 注解注入 -->
    <context:annotation-config></context:annotation-config>
    <context:component-scan base-package="com.liantuo.hotel.common.service.impl" />
    <context:component-scan base-package="com.liantuo.hotel.common.dao.ibatis" />
    <context:component-scan base-package="com.liantuo.hotel.app.dao.ibatis" />
    <context:component-scan base-package="com.liantuo.hotel.app.service" />
    <context:component-scan base-package="com.liantuo.hotel.app.service.ibatis" />
    @Component(组件)@Service(服务层)@Controller(控制层)@Repository(数据库访问层)
    3.有了<context:component-scan>,另一个<context:annotation-config/>标签根本可以移除掉,因为已经被包含进去了。
    <context:component-scan>提供两个子标签:<context:include-filter>和<context:exclude-filter>各代表引入和排除的过滤。
    <context:component-scan base-package="com.xhlx.finance.budget" >

    <context:include-filter type="regex" expression=".service.*"/>
    </context:component-scan>

    filter标签在Spring3有五个type,如下:

    Filter Type

    Examples Expression Description
    annotation org.example.SomeAnnotation 符合SomeAnnoation的target class
    assignable org.example.SomeClass 指定class或interface的全名
    aspectj org.example..*Service+ AspectJ语法
    regex org.example.Default.* Regelar Expression
    custom org.example.MyTypeFilter Spring3新增自訂Type,实作org.springframework.core.type.TypeFilter
  • 相关阅读:
    Fancybox丰富的弹出层效果
    oracle wm_concat(column)函数的使用
    asp.net下ajax.ajaxMethod使用方法
    sql2008 附加数据库出错解决方法
    关于mysql-5.7.13-winx64服务无法启动的解决方法
    解决懒加载异常
    学生各科成绩,平均分,总分的展示
    docker desktop v20 设置文件路径,windows docker 设置设置路径
    自动化运维工具:jumpserver/jms_all
    linux kill 进程正则表达式
  • 原文地址:https://www.cnblogs.com/soundcode/p/6476958.html
Copyright © 2011-2022 走看看