继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

Spring 一二事(5) - 依赖注入

2018-05-10 11:48:253923浏览

风间影月

10实战 · 54手记 · 8推荐
TA的实战
<!-- 依赖注入的装配过程 -->
    <bean id="person" class="com.lee.spring007.di.xml.setter.Person">
        <property name="pid" value="1001"></property>

        <property name="name" value="nathan"></property>

        <property name="stu" ref="student"></property>

        <property name="list">
            <list>
                <value>a</value>
                <value>b</value>
                <value>c</value>
                <value>d</value>
                <value>e</value>
            </list>
        </property>

        <property name="map">
            <map>
                <entry key="number" value="111"></entry>
                <entry key="bean" value-ref="student"></entry>
            </map>
        </property>

        <property name="properties">
            <props>
                <prop key="one">111</prop>
                <prop key="two">222</prop>
                <prop key="three">333</prop>
            </props>
        </property>

        <property name="sets">
            <set>
                <value>11</value>
                <ref bean="student" />
            </set>
        </property>

        <property name="obj">
            <list>
                <value>a</value>
                <value>b</value>
                <value>c</value>
                <value>d</value>
                <value>e</value>
            </list>
        </property>

    </bean>
    <bean id="student" class="com.lee.spring007.di.xml.setter.Student"></bean>
package com.lee.spring007.di.xml.setter;

import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

public class Person {
    private int pid;
    private String name;
    private Student stu;
    private List list;
    private Set sets;
    private Map map;
    private Properties properties;
    private Object[] obj;
    public int getPid() {
        return pid;
    }
    public void setPid(int pid) {
        this.pid = pid;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public Student getStu() {
        return stu;
    }
    public void setStu(Student stu) {
        this.stu = stu;
    }
    public List getList() {
        return list;
    }
    public void setList(List list) {
        this.list = list;
    }
    public Map getMap() {
        return map;
    }
    public void setMap(Map map) {
        this.map = map;
    }
    public Properties getProperties() {
        return properties;
    }
    public void setProperties(Properties properties) {
        this.properties = properties;
    }
    public Object[] getObj() {
        return obj;
    }
    public void setObj(Object[] obj) {
        this.obj = obj;
    }
    public Set getSets() {
        return sets;
    }
    public void setSets(Set sets) {
        this.sets = sets;
    }

}
package com.lee.spring007.di.xml.setter;

public class Student {

    public static void say() {
        System.out.println("I am a student!");
    }
}
打开App,阅读手记
“小礼物走一走,来慕课关注我”
赞赏支持
风间影月说
去围观
创业公司技术总监, 10年+开发和技术管理经验。SUN认证SCJP、PMP、MCP认证。主要从事后端技术和架构领域,有丰富的电商平台与物流平台核心系统的架构设计和开发经验。
发表评论
随时随地看视频慕课网APP