本文共 911 字,大约阅读时间需要 3 分钟。
package shangbo.spring.core.example26;public class Person { private String name = "Shangbo"; private int age = 30; // // Setter // public void setName(String name) { this.name = name; } public void setAge(int age) { this.age = age; } public String toString() { return "[name=" + name + ", age=" + age + "]"; }}
package shangbo.spring.core.example26;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;public class App { public static void main(String[] args) { // 实例化 Spring IoC 容器 ApplicationContext context = new ClassPathXmlApplicationContext("example.xml", Person.class); // 从容器中获得 Person 对象 Person p = context.getBean(Person.class); // 使用对象 System.out.println(p); }}
–
– 声 明:转载请注明出处 – Last Updated on 2017-06-17 – Written by ShangBo on 2017-05-22 – End