实例化域对象的常规做法是什么?假设在如下的体系结构中:
@RestController
public class MyController implements ServletConfigAware {
private ApplicationContext context;
@RequestMapping(value="/getNewObject")
public MyBusinessObject getANewObject(){
MyService service = (MyService)context.getBean("myService);
return service.getNewObject();
}
public class MyService {
private ApplicationContext context;
public MyBusinessObject getNewObject(){
return new MyBusinessObject();
vs
(MyBusinessObject)context.getBean("myBusinessObject");
vs
(MyBusinessObject)context.getBean("myBusinessObjectFactory").createNewMyBusinessObject(); //Factory is another class which returns a 'new' object
}
}
public class MyBusinessObject { }
我是否以预期的方式使用弹簧IOC?