1.注解类
@Component(value = "MyTestBean") public class MyTestBean { private String name = "11"; public String getName() { return name; } public void setName(String name) { this.name = name; } }
2.调用
ApplicationContext context=new AnnotationConfigApplicationContext("com.jd.xq.bean"); MyTestBean start= (MyTestBean) context.getBean("MyTestBean"); System.out.println(start.getName());