zoukankan      html  css  js  c++  java
  • spring的注入方式

    在spring对类进行注入时主要有通过属性,构造函数,以及自动注入方式,还可在beans根标签中使用default-autowire="byName|byType|..."来对beans中的所有bean进行自动注入

    1. 通过属性注入使用<propety id="xxx" ref="">的方式
    2. 通过构造方法使用<constructor-arg ref="xxx">如果构造方法中有多个参数则依次使用此标签<constructor-arg ref="arg1"><constructor-arg ref="arg2">
    3. 自动注入在<bean id="xx" class="xxx.xx" autowire="xx">xx可为byName,byType.default,no,constructor使用byType时,注意不应用两个相同类型的类,否则会抛异常。

    可使用

      <bean id="xx" class="xxx.xx">
            <property name="xx" value="xx"></property>
            <property name="xx" value="xx"></property>
            <property name="xx" value="xx"></property>
        </bean>

    来注入一个对象property中的name为id为xx对象的属性名,value则为属性值

    也可注入集合

    <propety name="xx">

    <list>

    <value>xx</value>

    <value>xx</value>

    <ref></ref>

    </list>

    </property>

  • 相关阅读:
    使用yum时,保留下载包设置
    df命令
    Linux Shell脚本实现根据进程名杀死进程
    centos 清理内存缓存
    sgdisk常用操作
    CentOS7 bonding配置
    linux下显示dd命令的进度:
    OSD磁盘日常监控
    flashcache
    Elasticsearch request body检索
  • 原文地址:https://www.cnblogs.com/charleszhang1988/p/3045935.html
Copyright © 2011-2022 走看看