首页 > 技术文章 > 函数式创建对象交给Spring管理

Dasnl 2021-04-02 23:21 原文

public class Testal {
@Test
//函数式 创建对象交给Spring 管理。
public void Test2(){
GenericApplicationContext te = new GenericApplicationContext();
te.refresh();
te.registerBean(Book.class,()-> new Book());
Book b= (Book) te.getBean("Zhouxinhua.Book");
System.out.println(b);
}
}

推荐阅读