在我的Spring MVC应用程序中,我有一个' DrawingController'它接受来自客户端的MultipartHttpRequests。
用户可以从前端上传任何类型的图纸(暂时只有自动CAD和bim图纸)。
有一个名为' DrawingService'和两个实现' BIMDrawingService'和' CADDrawingService'如下。
public interface DrawingService{
public String manageUpload();
}
@Component("bimService")
public class BIMDrawingService implements DrawingService{
public String manageUpload() {//}
}
@Component("cadService")
public class CADDrawingService implements DrawingService{
public String manageUpload() {//}
}
public class DrawingController {
@Autowired
@Qualifier("bimService")
private DrawingService bimService;
@Autowired
@Qualifier("cadService")
private DrawingService cadService;
public void setDrawingService(DrawingService bimService) {
this.bimService= bimService;
}
@RequestMapping(value = "/upload", method = RequestMethod.POST)
public @ResponseBody String handleFileUpload(MultipartHttpServletRequest request){
//if request type == BIM, then ignore the logic how I differentiate
if bimrequest
bimService.manageupload()
else if cadrequest
cadService.manageupload()
}
我觉得这不是一个好方法,我的问题是如何在运行时动态注入服务,即使我稍后添加新的绘图服务,我应该能够进行最小的更改。请给我一些最好的设计解决方案。