在以下情况下如何通过 spring 注入。
Class A{
public void doSomeThing(){
B builder=new B();
//call other function.
}
}
在这里,我不想将 B 作为类级别的对象。
Class A{
B b;// dont want to bring b here
}
我也不想使用 Spring context.getBean("B) 或 autowire;
所以 Spring 必须以以下方式注入 B:
Class A{
public void doSomeThing(){
B builder=<injected by Spring>
//call other function.
}
}
所以 B 在 doSomeThing() 方法的范围内被创建和销毁。