spring 入门

一、java 代码

public class Student {
    
    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

二、applicationContext.xml

<bean id = "student" class = "com.Student"></bean>

三、测试代码

@Test
public void test3(){
    //初始化 spring 容器
    ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:spring/applicationContext.xml");
    //从容器中获得 jedisClient 对象
    Student student = applicationContext.getBean(Student.class);
    student.setName("张三");
    String name = student.getName();
    System.out.println(name);
}
原文地址:https://www.cnblogs.com/fangwu/p/8644806.html