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);
}

 

posted @ 2018-03-25 15:15  方方方方方方  阅读(89)  评论(0编辑  收藏  举报