package com.yyf.pojo;
public class Hello {
private String str;
public String getStr() {
return str;
}
public void setStr(String str) {
this.str = str;
}
@Override
public String toString() {
return "Hello{" +
"str='" + str + ''' +
'}';
}
}
2.配置applicationContext.xml 创建bean 并为str属性赋值 Spring
3.测试类
import com.yyf.pojo.Hello;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class MyTest {
public static void main(String[] args) {
//获取Spring的上下文对象
ApplicationContext context = new ClassPathXmlApplicationContext ("beans.xml");
//我们的对象都在spring中管理了,要使用直接去里面拿就好了
Hello hello =(Hello) context.getBean ("hello");
System.out.println (hello.toString ());
}
}



