Spring Di依赖注入环境

小新
2022-01-05 / 0 评论 / 384 阅读 / 正在检测是否收录...

构造器注入

前面已经了解了

set 方式注入

搭建环境

1.复杂类型

package com.xyh.pojo;

public class Address {
    private String address;

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    @Override
    public String toString() {
        return "Address{" +
                "address='" + address + '\'' +
                '}';
    }
}

2.测试对象类

package com.xyh.pojo;

import java.util.*;

public class Student {
    private String name;
    private Address address;
    private String[]books;
    private List<String> hobbys;
    private Map<String,String> card;
    private Set<String> games;
    private String wife;
    private Properties info;
}

3.ApplicationContext.xml

4.测试类

public class MyTest {
    public static void main(String[] args) {
        ApplicationContext context = new ClassPathXmlApplicationContext("ApplicationContext.xml");
        Student student = (Student) context.getBean("student");
        System.out.println(student);
    }
}

截图展示

ky1h7dux.png

0

评论 (0)

取消